2014-11-14 32 views
0

我使用jquery.iframe-transport.js使用iframe &上載文件的Ajax(使用Internet Explorer) 文件被正確上傳和服務器用適當的後響應每個呼叫的響應。但是,回調函數「complete」中的響應「data」始終包含previous/older響應。即使清除緩存並使用新的瀏覽器似乎也沒有幫助。任何想法必須發生什麼?服務器響應不正確反映後,阿賈克斯後

$(function() { 
    //alert("Loading"); 

    getLDAPUsers(); 
    //getDummyUsers(); 

    //This will submit the file content using Ajax via Iframe 
    $("#myForm").submit(function() { 
     alert("Submitting Ajax"); 
     $.ajax(this.action, { 
      data: $(":text", this).serializeArray(), 
      files: $(":file", this), 
      //iframe: true, 
      processData:false 
     }).complete(function(data) { 
     debugger; 
      alert("Response from server ::: "+data.responseText); 
     }); 
    }); 
+0

它看起來像你錯過了你的[即時函數調用尾隨'()' ](http://stackoverflow.com/questions/939386/immediate-function-invocation-syntax)。 – b4hand

回答

0

我會建議你用「成功」和「錯誤」來代替,例如:

$(function() { 
    $("#myForm").on('submit',function(event) { 
    event.preventDefault(); 

    //alert("Loading"); 

    getLDAPUsers(); 
    //getDummyUsers(); 

    var request = $.ajax({ 
     type: 'POST', 
     url: $(this).attr('action'), 
     data: $(":text", this).serializeArray(), 
     files: $(":file", this), 
     //iframe: true, 
     ifModified: true, 
     cache: false, 
     success: function (response, textStatus, xhr) { 
     alert("Response from server ::: "+response); 
     }, 
     error: function (xhr, textStatus, errorThrown) { 
     alert('ERROR'); 
     } 
    }); 
    }); 
})(); 
+0

...我注意到你的$('#myForm')。submit(function(){});並沒有停止正常的表單提交,這可以這樣完成: $('#myForm')。submit(function(e){ e.preventDefault(); $ .ajax(this.action,{ 。 ... ... }); }); – Kirbo

+0

謝謝你們,但這兩種解決方案似乎都不起作用。我指的是 - http://cmlenz.github.io/jquery-iframe-transport/ – Aditi

+0

我現在可以讓回撥工作。但是,我發現在執行Ajax帖子時發送了2個http請求。其中一個是不包含任何文件信息的GET,另一個是POST,它是包含文件內容的實際請求。回調「完成」是從GET調用接收響應,這顯然不是我想要的。我無法確定爲什麼發送GET請求!有什麼建議麼?只需補充一點,我正在使用IE9 – Aditi