0
如何將進度事件偵聽器添加到原型Ajax請求中?如何將進度事件偵聽器添加到原型Ajax請求中?
我沒有找到有關此內容的原型DOC什麼..
我發現使用jQuery一些示例,但不與原型。
new Ajax.Request('/some_url', {
method:'get',
onSuccess: function(transport) {..},
onFailure: function() {..}
});
使用jQuery:
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
// Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded/evt.total;
//Do something with upload progress
console.log(percentComplete);
}
}, false);
// Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded/evt.total;
// Do something with download progress
console.log(percentComplete);
}
}, false);
return xhr;
},
type: 'POST',
url: "/",
data: {},
success: function(data){..}
});
感謝一個例子!我還加了't.transport.onprogress = function(event){..}' – vhanahrni