義烏做網(wǎng)站ajaxSubmit插件jQuery1.4.2版JSON問(wèn)題

2012-01-01 瀏覽:150
義烏做網(wǎng)站ajaxSubmit插件jQuery1.4.2版JSON問(wèn)題:

jQuery Form 插件基于jQuery v1.4.2版返回JSON數(shù)據(jù)時(shí)一直報(bào)錯(cuò);修改以下內(nèi)容可恢復(fù);

原后臺(tái)輸出數(shù)據(jù)格式如:{sitename:'開(kāi)發(fā)者網(wǎng)絡(luò)',siteurl:'www.AAA.net',level:10} 需改為 {"sitename":"開(kāi)發(fā)者網(wǎng)絡(luò)","siteurl":"www.AAA.net","level":10}

也就是在名稱(chēng)需以雙引號(hào)包括;因?yàn)?jQuery 1.4.2版在 parseJSON 方法中添加了正則判斷

if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
   .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
   .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) {
   // Try to use the native JSON parser first
   return window.JSON && window.JSON.parse ?
    window.JSON.parse( data ) :
    (new Function("return " + data))();

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


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);
    }

 

上一條: 義烏網(wǎng)站制作網(wǎng)頁(yè)HTML默認(rèn)的CSS樣式表屬性
下一條: 義烏做網(wǎng)站域名購(gòu)買(mǎi)常規(guī)事項(xiàng)

新聞資訊

相關(guān)資訊