2013-12-17 39 views
0

我遇到與IE相關的jQuery和ajax問題。 Chrome和Firefox工作得很好,但我的ajax調用正在IE中消失。IE 9,10,11 - Ajax調用不返回

完成ajax調用後,successfail函數都不會被調用。我可以在IE控制檯中看到響應,並且我知道我的控制器操作正在被觸發。

$.ajax({ 
    url: controllerUrl 
    type: 'POST', 
    dataType: 'json', 
    cache: false, 
    data: { 
     id: customerId 
    }, 
    success: function() { 
     alert('success!'); 
    }, 
    error: function() { 
     alert('failed!'); 
    } 
}); 

有沒有其他人看過這個問題?

+0

失敗()是承諾接口的方法:'$阿賈克斯({...}) .fail(function(){alert('failed!');});' –

+0

您是否看到開發工具中的AJAX請求觸發?你確定它返回有效的JSON嗎?它在同一個域上嗎? –

+0

按F12並刷新頁面並嘗試ajax請求後讀取控制檯。 –

回答

2
fail: function() { 
     alert('failed!'); 
    } 

fail不是有效的jQuery ajax設置。我相信你正在尋找error

另外,cache: false,POST請求無關。

請注意,jQuery 不會附加POST請求的時間戳。

源代碼清楚地證明了這一點。 (從https://github.com/jquery/jquery/blob/master/src/ajax.js總結)

var rnoContent = /^(?:GET|HEAD)$/; 
s.hasContent = !rnoContent.test(s.type); 
if (!s.hasContent) { 
    /* code to append time stamp */ 
} 
+1

'cache:false'確實在帖子上做了些什麼......它附加了一個時間戳作爲URL參數 – FastTrack

+0

@FastTrack你是如何確定的? =) –

+0

http://api.jquery.com/jQuery.ajax/:'將緩存設置爲false將只能正確處理HEAD和GET請求...該參數對於其他類型的請求不需要,除了在IE8時一個POST是由一個已經被GET請求的URL創建的。' –

0

你缺少一個逗號,你的URL參數後:

$.ajax({ 
    url: controllerUrl, // <--- you were missing this comma! 
    type: 'POST', 
    dataType: 'json', 
    cache: false, 
    data: { 
     id: customerId 
    }, 
    success: function() { 
     alert('success!'); 
    }, 
    error: function() { 
     alert('failed!'); 
    } 
}); 
+1

如果第一個逗號缺失,它將無法使用*任何*瀏覽器。 –

+0

@BradM絕對不是真的。我之前曾多次看到過這個多次AJAX調用。 – FastTrack

+1

@FastTrack:我很懷疑。 http://jsfiddle.net/LGN7J/ –