Web方法返回正常,但触发失败功能 [英] Web method return OK but fire fail function
本文介绍了Web方法返回正常,但触发失败功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的网络方法
[HttpGet]
public ActionResult EditEmp(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Employee Emp = db.Employees.Find(id);
if (Emp == null)
{
return HttpNotFound();
}
ViewBag.dept_id = new SelectList(db.Departments, "dept_id", "dept_name", Emp.dept_id);
return PartialView("_EditEmp", Emp);
}
这是ajax调用
$.ajax({
type: "GET",
url: '/Employee/EditEmp',
data: { id: idp },
dataType: "json",
success: function (result) {
alert(result);
$('#editid').html(result);
},
error: function (result) {
alert("FAILED : " + result.status + ' ' + result.statusText);
}
});
它给了我result.status = 200和result.statusText = OK,但它引发了错误事件
it gives me result.status =200 and result.statusText = OK but it fire Error Event
推荐答案
请检查您是否返回了有效的json,因为您正在设置
Please check that you are returning valid json or not, because you are setting
dataType:"json"
dataType: "json"
它将响应评估为JSON并返回一个JavaScript对象. (...)严格解析JSON数据;任何格式错误的JSON都会被拒绝,并引发解析错误.
it evaluates the response as JSON and returns a JavaScript object. (...) The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown.
您可能想看看此
这篇关于Web方法返回正常,但触发失败功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文