The jQuery Form plug-in keeps reporting an error when returning JSON data based on jQuery v1.4.2; it can be restored by modifying the following content;
The original background output data format is such as: {sitename:'Developer Network',siteurl:'www.AAA.net',level:10} needs to be changed to {"sitename":"Developer Network","siteurl":"www .AAA.net","level":10}
That is, the name needs to be enclosed in double quotes; because jQuery version 1.4.2 added regular judgment in the parseJSON method
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 { |
What needs to be modified in the jQuery Form plug-in
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); } |
Modify to:
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); } |
Original address: http://www.vifo.net/Program/JavaScript/10090191.shtml