一般跨域请求,页面上都以post方式提交,$.getJSON方法是get方法提交的,所以getJSON方法一般不用在跨域。 (1)页面上引入jQuery.windowName.plugin.js文件, (2)服务器返回的类型要做下包装成下面这样的样式: <script>window.name='{"code":-1,"message":"非法提交"}'</script> (3) ajax的回调函数里,要对返回值做eval处理,转成json对象 var data = eval("("+returnStr+")"); //转换为json对象 如一个示例: Js代码 $.post('${API_ROOT}/sendVerificationCode.jsp?act=getPassword&mobile=' + mobile + '&callback=windowname',function(returnStr){ var data = eval("("+returnStr+")"); //转换为json对象 if(data.code == 0){ $("#checkTips").empty(); $("#checkTips").html("验证码已发送到您绑定的手机<strong id='mobileNo' class='orange'>" + decodedMoile + "</strong>上,请在下方输入验证码"); setVerificationInvalid(); } else { showErrorTips(data.message); inableVerBut(); } }); |
|
来自: 啧啧w0i0q7a0t7 > 《待分类》