1

这是我用来从 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 中正常工作。

4

1 回答 1

3

数据类型应该是json

 dataType: "json",

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

并尝试更改application/json; charset=utf8为 plain application/json

于 2012-10-03T05:18:46.737 回答