【发布时间】:2020-12-25 00:09:59
【问题描述】:
检查下面的jquery 代码。在此处理后请求 response 返回 no_file_found 但如果条件不满足且未达到 alert()。我在这里做错了什么?
$("#btnFoo").on("click", function () {
var file_data = $('#formUploadImg').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
form_data.append('ProId', $(this).attr("img-upload-product-id"));
$.ajax({
url: '/mycontroller/upload',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (response) {
console.log(typeof response);//it returns string
if (response == "no_file_found") {
alert("this not hits");//this alert not hits
}
},
error: function (response) {
alert("Error");
}
});
});
请注意我正在使用 c# mvc5 并且响应来自 mvc5 控制器。 Mvc5 示例如下:
[HttpPost]
public JsonResult upload()
{
return Json("no_file_found");
}
【问题讨论】:
-
检查
console.log(response, response == "no_file_found")... 这个日志记录“no_file_found”是真的吗? -
它显示:
"no_file_found" false以及为什么它是错误的任何提示?
标签: javascript c# jquery asp.net-mvc-5