这是我用来从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"
}
但是,如果我执行$.parseJSON
或eval
来解析JSON响应,它会终止自身的执行。这只发生在IE中,它在FF和Chrome中正常工作。
答案 0 :(得分:3)
数据类型应为json
dataType: "json",
在IE
中,当您未指定dataType时,这会导致问题。
并尝试将application/json; charset=utf8
更改为普通application/json
。