jQuery Form 外掛程式基於jQuery v1.4.2版傳回JSON資料時一直報錯;修改以下內容可恢復;
原後台輸出資料格式如:{sitename:'開發者網路',siteurl:'www.AAA.net',level:10} 需改為{"sitename":"開發者網路","siteurl":"www .AAA.net","level":10}
也就是在名稱需以雙引號包含;因為jQuery 1.4.2版在parseJSON 方法中加入了正規判斷
if ( /^[],:{}s]*$/.test(data. replace(/\(?:[" \/bfnrt]|u[0-9a-fA-F]{ 4})/g , "@") .replace(/"[^" \nr]*"|true|false|null|-?d+(?:.d*)?(?:[eE][+-]? d+)?/g , "]") .replace(/(?:^|:|,)(?:s*[)+/g, "")) ) { // Try to use the native JSON parser first } else { |
jQuery Form 外掛程式需要修改的地方
if (scr || s.textarea) { // see if user embedded response in textarea var ta = doc.getElementsByTagName('textarea')[0]; if (ta) { xhr.responseText = ta.value; } else if (scr) { // account for browsers injecting pre around json response var pre = doc.getElementsByTagName('pre')[0]; if (pre) { xhr.responseText = pre.innerHTML; } } } else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) { xhr.responseXML = toXml(xhr.responseText); } |
修改為:
if (scr || s.textarea) { // see if user embedded response in textarea var ta = doc.getElementsByTagName('textarea')[0]; if (ta) { xhr.responseText = ta.value; } else if (scr) { // account for browsers injecting pre around json response var pre = doc.getElementsByTagName('pre')[0]; if (pre) { xhr.responseText = pre.innerHTML; } else xhr.responseText=doc.body.innerHTML; } } else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) { xhr.responseXML = toXml(xhr.responseText); } |
原文網址:http://www.vifo.net/Program/JavaScript/10090191.shtml