function queryCredit(id,riskWay,successCallMethod){ $.ajax({ type: "GET", async: true, url: "http://local.t100.com:8080/risk/query?id=32", success: function(data) { $("#result_div").html(data); } }); }
两个项目依赖的jquery.js版本不一样,同样的代码在不同的项目中结果不一样。
此js代码在一个项目中【jquery版本:jquery-1.8.0.min.js中(jquery-1.8.0.min.js)】是能正常运行的,result_div能正常显示请求响应的结果。
而在另一个项目,jquery.js版本是:【/*! jQuery v1.11.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */】,result_div不显示请求响应的结果。
在谷歌浏览器(IE也一样)result_div中没有正常显示返回的结果。看网络请求的响应正常,也没有console中的js报错。如下:
换成火狐浏览器,终于看到了如下的报错信息:
SyntaxError:JSON.parse: unexpected character at line 1 column 1 of the JSON data
定位到原因后,在ajax参数加上dataType:"html"后,程序按照预期正常执行。
function queryCredit(id,riskWay,successCallMethod){ $.ajax({ type: "GET", async: true, dataType:"html", url: "http://local.t100.com:8080/risk/query?id=32", success: function(data) { $("#result_div").html(data); } }); }