[jQuery] .ajax 在 IE7 中無法執行 success 函式

如果使用 jQuery .ajax 時發現在 IE7 內無法執行 success 函式,可以使用以下方法解決:

  1. js 的部份,請在 dataType 加上判斷式如下:
  2. dataType: (jQuery.browser.msie) ? "text/xml" : "text"

  3. 後端程式如 php 的部份,使用 header 宣告文件的 Content-type 為 xml:
  4. header('Content-type: text/xml');

相關的問題在 jQuery 官方文件有一篇 Using the right MIME type 可以參考。但我自己遇到的狀況是將 dataType 宣告為 text 時,在 IE7 內仍然無法成功執行 success 函式,改為 text/xml 才解決了問題。

可能的相關文章:

 
 
 

歡迎留言: