当前位置: 代码迷 >> JavaScript >> 怎么解析从服务器返回的json
  详细解决方案

怎么解析从服务器返回的json

热度:79   发布时间:2012-04-02 19:58:59.0
如何解析从服务器返回的json?


看下面的两个alert()吧


JScript code

function afterApply() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var response = xmlHttp.responseText;alert(response);
            var ret = eval(response);
            alert(response); // 打印的数据是{"code":1,"msg":"美丽的错误"}
            alert(ret);      // 这里出错了!!!!!!!!!!!
            document.getElementById("apply_authcode").style.display='none';
            document.getElementById("apply_success").style.display='block';
        }
    }
}











------解决方案--------------------
var ret = eval("("+response +")"); 改为这样试试。
  相关解决方案