Reputation: 93
I have a jquery.ajax object in which I want to substitute xhr. However executing the following code gives me an error:
TypeError: Property 'xhr' of object #<Object> is not a function
The relevant code is:
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();
}
});
Upvotes: 3
Views: 2238
Reputation: 30453
xhr
is used in other way. See documentation: 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.
May be you're looking for something like
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.upload.addEventListener('progress', calendar.check_progress, false);
return myXhr;
},
Upvotes: 2