ajax then progress,GitHub - hiddentao/jquery.ajaxprogress: jQuery AJAX Progress plugin

AJAX Progress plugin for jQuery

This plugin enhances the jQuery AJAX request handler with the ability to display a user-specified progress indicator if the request takes longer than a user-specified time to complete. The motivation for adding such functionality is that sometimes the AJAX requests take longer than expected (especially on mobiles with patchy connections) and it would be good to be able to inform the user of such a delay in an easily re-usable manner.

Once enabled two new settings are available for the $.ajax call:

progress_indicator

Either a jQuery object, function callback or a HTML string specifying the progress indicator. If not specified then no progress indicator will be shown.

progress_indicator_delay

No. of milliseconds to wait from when the AJAX request has been sent before displaying the progress indicator. Default is 1000, i.e. 1 second.

The progress indicator can be one of the three types:

jQuery object:

show() will be called on it when the request is in progress and hide() will be called on it once the request completes.

Callback function:

it will be invoked with its argument as false (boolean) when the request is in progress and it will then be invoked with true (boolean) when the request has completed.

HTML string:

it will be added to the body within a DIV when the request is in progress. The DIV will then be removed once the request has completed. The DIV has the 'ajax_progress_indicator' class set on it so you can style it as you wish using CSS.

Example: function callback

Use a function callback to toggle the visiblity of an element, 0.5 seconds after the AJAX request has started.

$.ajax({

progress_indicator : function(state) { $("#progress).toggle(state); },

progress_indicator_delay : 500,

... /* other AJAX params here */

});

Example: jQuery object

Use a jQuery object.

$.ajax({

progress_indicator : $("#progress),

... /* other AJAX params here */

});

Example: HTML string

Use a HTML string, to show after 5 seconds.

$.ajax({

progress_indicator : "Sorry, this request is taking a long time.",

progress_indicator_delay : 5000,

... /* other AJAX params here */

});

Example: no indicator

If you don't supply the progress indicator parameters then it doesn't get shown.

$.ajax({

... /* other AJAX params here */

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值