我有一个 jquery.ajax 对象,我想在其中替换 xhr。但是执行以下代码会给我一个错误:
TypeError: Property 'xhr' of object #<Object> is not a function
相关代码为:
var req = jQuery.ajaxSettings.xhr();
req.upload.addEventListener('progress', calendar.check_progress, false);
$.ajax({
url: script_root + '_save_file/'+id+'/'+timestamp,
type: 'POST',
processData: false,
contentType: false,
data: fd,
xhr: req,
success: function(data){
do_something();
},
error: function(data){
console.log(data);
do_something_else();
}
});
最佳答案
xhr
以其他方式使用。请参阅文档:http://api.jquery.com/jQuery.ajax/
xhr: Function
Default: ActiveXObject when available (IE), the XMLHttpRequest otherwise
Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttpRequest or enhancements to the factory.
也许你正在寻找类似的东西
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.upload.addEventListener('progress', calendar.check_progress, false);
return myXhr;
},
关于javascript - jQuery.ajax : TypeError: Property 'xhr' of object #<Object> is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12374326/