这是我的ajax电话:
jQuery.ajaxFileUpload({
url: App.CONTEXT_PATH + "/candidate/uploadPhoto",
fileElementId: 'photoFile',
dataType: 'json',
success: function (result) {
if (!result) {
return;
}
var code = result.code;
if (code == 1) {
var fileName = result.data;
$("#imageFileName").val(fileName);
$(".display_pic img").attr("src", App.UPLOAD_URL + "/" + fileName);
alert("Image Path: " + App.UPLOAD_URL + "/" + fileName);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
弹出此错误:TypeError:数据未定义。我用Firebug调查了响应并看到了正确的响应如下:
{"data":"f95eed76-0fdb-4b45-bbb8-dfae8b7f548awebapp.png","code":1}
出现此错误的原因是什么?
答案 0 :(得分:0)
我真的不确定这一点,但您可以尝试将结果信息立即存储到变量中然后继续处理。
jQuery.ajaxFileUpload({
url: App.CONTEXT_PATH + "/candidate/uploadPhoto",
fileElementId: 'photoFile',
dataType: 'json',
success: function (result) {
var temporary = result;
if (!temporary) {
return;
}
var code = temporary.code;
if (code == 1) {
var fileName = temporary.data;