Js代码
- JScript code
$.ajax({ type: "POST", url: "/Ajax/PhoneNumber", data: { number: $("#number").val().substring(0, 7) }, contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(msg.message); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("Status:" + XMLHttpRequest.status + " readyState:" + XMLHttpRequest.readyState + " textStatus:" + textStatus); } });
Controller代码
- C# code
[HttpPost] public JsonResult PhoneNumber(string number) { string value = BLL.PhoneNumberInfo.Get(number); return Json(new { message = value }, JsonRequestBehavior.AllowGet); //return Content(value); }
当加入contentType: "application/json; charset=utf-8"时,就会返回500错误
使用默认"application/x-www-form-urlencoded"时就会正常返回json
请问这是什么原因呢?
------解决方案--------------------------------------------------------
500错误是服务器端错误。看你服务器端程序有什么问题了。
------解决方案--------------------------------------------------------
500 好像是返回的字符串有html吧?
------解决方案--------------------------------------------------------