• ajaxSubmit插件jQuery1.4.2版JSON问题


    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(/"[^"\\\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);
        }

    http://www.hua126.com/article/edu/Web/info-10356.html

  • 相关阅读:
    ajax异步服务器获取时间
    JavaScript基本知识
    JavaScript使用button提交表单
    spring与hibernate整合
    Spring的事务属性
    注解方式实现Spring声明式事务管理
    svn的安装使用
    sbn
    恢复oracle中误删除drop掉的表
    ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes的解决办法
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839187.html
Copyright © 2020-2023  润新知