【发布时间】:2014-03-27 17:31:55
【问题描述】:
我已经尝试过创建自己的 jquery 函数,这是通过
$.fn.extend({
myFunc: function () {
}
});
但是,在网上搜索并寻找答案后,我想问一下:
如何扩展 $.ajax()
$.ajax的新实现可以通过运行来使用
$.ajax({
}).done(function (e) {
}).fail(function (e) {
});
我想做的是添加一个.progress(),这样我就不必总是写了
$.ajax({
url: path,
xhrFields: {
onprogress: function (e) {
if (e.lengthComputable) {
console.log(e.loaded /e.total * 100 + '%');
}
}
}
});
每次我想监控进度。例如
$.ajax({
url: '/somewhereorother',
type: 'post',
dataType: 'json'
}).progress(function (e) {
updateProgressBar(e.percentage + '%');
}).done(function (e) {
}).fail(function (e) {
});
【问题讨论】:
-
jQuery 已经有deferred.progress() ?
-
好的,它会在我上面描述的上下文中工作吗?怎么样以供将来参考以作其他用途
标签: javascript jquery ajax extend