2013-04-08 33 views
1

我有一個MVC 4應用程序,其中包含一個帶有多個字段集的窗體。當我在Chrome中發佈此表單時,它可以毫無誤差地保存。在IE 10.0.92中,我在以下jQuery方法中遇到錯誤。拋出錯誤的行有一個箭頭。這大致是538行。我確定這個方法在Chrome中執行時甚至沒有調用。jQuery 1.9.1錯誤 - 與IE發生但不是Chrome發生

parseJSON: function (data) { 
    // Attempt to parse using the native JSON parser first 
    if (window.JSON && window.JSON.parse) { 
-->  return window.JSON.parse(data); 

    } 

    if (data === null) { 
     return data; 
    } 

    if (typeof data === "string") { 

     // Make sure leading/trailing whitespace is removed (IE can't handle it) 
     data = jQuery.trim(data); 

     if (data) { 
      // Make sure the incoming data is actual JSON 
      // Logic borrowed from http://json.org/json2.js 
      if (rvalidchars.test(data.replace(rvalidescape, "@") 
       .replace(rvalidtokens, "]") 
       .replace(rvalidbraces, ""))) { 

       return (new Function("return " + data))(); 
      } 
     } 
    } 

    jQuery.error("Invalid JSON: " + data); 
}, 

我得到的錯誤是:

​​

我做了提醒。「數據」的價值,我也得到一個未定義的。我對jQuery或JavaScript沒有太多的經驗。如果需要更多信息,我會很樂意提供。

經過進一步的測試,這種變化似乎解決這個問題,但我不知道這是正確的做法:

parseJSON: function (data) { 
    if (data === undefined) { 
     return data; 
    } 

    // Attempt to parse using the native JSON parser first 
    if (window.JSON && window.JSON.parse) { 
     return window.JSON.parse(data); 

    } 
+1

代碼試圖解析的JSON是什麼? – 2013-04-08 00:40:26

+0

這也發生在Opera中。或者,也許只有我們兩個面對它! – hjpotter92 2013-04-08 00:41:18

+0

IE 10.0.92。而且,我不知道我從客戶端向服務器發送任何JSON。也許間接地完成了。 – 2013-04-08 00:41:50

回答

1

更新jquery.validate.unobtrusive.js與Microsoft.jQuery文件。 Unobtrusive.Validation nuget包哪個版本是2.0.30506.0 然後這個錯誤已經解決了。