javascript - JSON 在 IE 中不起作用

标签 javascript jquery json

<分区>

这是我用来从 PHP 获取 JSON 响应的代码:

(function() {

var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');

$('#image-upload-form').ajaxForm({
    dataType: null,
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal)
        percent.html(percentVal);
        //console.log(percentVal, position, total);
    },
    complete: function(xhr) {
        status.html(xhr.responseText);
        var responseJSON = $.parseJSON(xhr.responseText);
        //var responseJSON = eval('('+xhr.responseText+')');

        /*var DOMElement = $(".progress-block-template").clone();
        var pagename = typeof($("#pagename").attr('value')=='undefined')?'':$("#pagename").attr('value');
        processingData(responseJSON,DOMElement,pagename);*/
    }
}); 

})();

这是使用 .html() 打印时得到的响应。

{
    "data": {
        "thumb_location": "http://XXXX.com/private/U/367/catalog/3/16285/thumbs/220x220.jpg?Expires=1349242125&Key-Pair-Id=APKAIGM4K33RYJKUHOXA&Signature=ptphhyF2GL6xe7xeosrzfKkpsXm7fWQAapcF3rjsZMuTwSCMhj2SZDIKtKGZ35-OJjTJ1LXu7wGEQlQvdKrBqT2oiOcPtL7etgTzRLe4~ub3KF64HhkglKv4DgzAWfvG5v8rNfmFvSja3HQ4K8m2o3h0Tl1uv7Lbwpqq0p71L5M_",
        "user_id": "367",
        "category_id": "3",
        "category_type": "worksample",
        "asset_id": 16285,
        "project_id": null,
        "file_name": "Chrysanthemum_37726.jpg",
        "size": 879394
    },
    "success": "true"
}

但如果我执行 $.parseJSONeval 来解析 JSON 响应,它会自行终止执行。这仅在 IE 中发生,并且在 FF 和 Chrome 中正常工作。

最佳答案

数据类型应该是json

 dataType: "json",

IE 中,当您未指定数据类型时,这会导致问题。

并尝试更改application/json; charset=utf8 到普通的 application/json

关于javascript - JSON 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12702256/

相关文章:

javascript - 使用任意 JavaScript 库查找相应单元格的 <td> 列值

php - 使用数据库信息更改文本的 CSS/外观

javascript - jquery count siblings 不返回正确的结果?

javascript - JQuery 添加具有最接近标签名称的类

json - 从 WebApi 获取 "No action was found"

javascript - 动态添加行并运行脚本

javascript - 如何在使用 JQuery 加载图像后运行代码

jquery - 是否可以使元素对 jquery 不可见

php - 使用 PHP 创建 JSON 数据并使用 jQuery 解析它

java - Jersey 客户端 - 如何通过 POST 请求以表单形式发送列表