Ajax Jquery returns 文件上传成功
Ajax File upload in Jquery returns success as result
我知道这听起来很傻,但我一直坚持使用控制器作为 Json 编辑 return 的任何值,即 1、0、true 或 false 并检查 ajax 文件上传成功部分数据它只包含 "Success" 作为值,无论控制器的 return 值是什么。
在这里,我使用 Ajax 文件上传,因为我从客户端上传文件。
控制器代码:
public ActionResult ImportExcelData(HttpPostedFileBase UploadExcel)
{
try
{
var Data = Repository.ImportData(filePath, OrgID);
return Json(true, JsonRequestBehavior.AllowGet);
}
catch(Exception)
{
return Json("false", JsonRequestBehavior.AllowGet);
}
}
查看代码:
$.ajaxFileUpload({
url: '@Url.Action("ImportData", "Lead")',
secureuri: false,
type: 'POST',
datatype: 'JSON',
contentType: "application/json; charset=utf-8",
cache: false,
fileElementId: "Upload",
success: function (data) {
//data contains only success as value.
}
});
谁能帮帮我,干杯。
终于解决了,当你 return 来自控制器的结果而不是 returning JSON 我使用 "Content(Value)".
控制器代码:
public ActionResult ImportExcelData(HttpPostedFileBase UploadExcel)
{
try
{
var Data = Repository.ImportData(filePath, OrgID);
if(sData!=null)
{
string sJSON = String.Join(",", sData);
return Content(sJSON);
}
else
{
return null;
}
}
catch(Exception)
{
return Json("false", JsonRequestBehavior.AllowGet);
}
}
在 ajax 文件上传成功部分,不是使用一个字符串获取数据,而是使用两个字符串,其中第二个字符串的值为 returned。这可能是因为 ajax 文件上传插件存在问题。
查看代码:
$.ajaxFileUpload({
url: '@Url.Action("ImportData", "Lead")',
secureuri: false,
type: 'POST',
datatype: 'JSON',
contentType: "application/json; charset=utf-8",
cache: false,
fileElementId: "Upload",
success: function (data,result) {
//"result contains your values.
}
});
我知道这听起来很傻,但我一直坚持使用控制器作为 Json 编辑 return 的任何值,即 1、0、true 或 false 并检查 ajax 文件上传成功部分数据它只包含 "Success" 作为值,无论控制器的 return 值是什么。
在这里,我使用 Ajax 文件上传,因为我从客户端上传文件。
控制器代码:
public ActionResult ImportExcelData(HttpPostedFileBase UploadExcel)
{
try
{
var Data = Repository.ImportData(filePath, OrgID);
return Json(true, JsonRequestBehavior.AllowGet);
}
catch(Exception)
{
return Json("false", JsonRequestBehavior.AllowGet);
}
}
查看代码:
$.ajaxFileUpload({
url: '@Url.Action("ImportData", "Lead")',
secureuri: false,
type: 'POST',
datatype: 'JSON',
contentType: "application/json; charset=utf-8",
cache: false,
fileElementId: "Upload",
success: function (data) {
//data contains only success as value.
}
});
谁能帮帮我,干杯。
终于解决了,当你 return 来自控制器的结果而不是 returning JSON 我使用 "Content(Value)".
控制器代码:
public ActionResult ImportExcelData(HttpPostedFileBase UploadExcel)
{
try
{
var Data = Repository.ImportData(filePath, OrgID);
if(sData!=null)
{
string sJSON = String.Join(",", sData);
return Content(sJSON);
}
else
{
return null;
}
}
catch(Exception)
{
return Json("false", JsonRequestBehavior.AllowGet);
}
}
在 ajax 文件上传成功部分,不是使用一个字符串获取数据,而是使用两个字符串,其中第二个字符串的值为 returned。这可能是因为 ajax 文件上传插件存在问题。
查看代码:
$.ajaxFileUpload({
url: '@Url.Action("ImportData", "Lead")',
secureuri: false,
type: 'POST',
datatype: 'JSON',
contentType: "application/json; charset=utf-8",
cache: false,
fileElementId: "Upload",
success: function (data,result) {
//"result contains your values.
}
});