2012-09-11 27 views
2

我有一個jquery.ajax對象,我想在其中替換xhr。然而執行以下代碼給我一個錯誤:jQuery.ajax:TypeError:屬性'xhr'對象#<Object>不是函數

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(); 
     } 
    }); 
+0

阿賈克斯方法按名稱XHR無功能:REQ ..這是搞亂你的要求 –

回答

1

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; 
}, 
+0

謝謝,看來要工作:) – effigiem

相關問題