[英]SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data?
[英]SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
调节器
[HttpGet]
public ActionResult VerifyUserEmail(string User_Email)
{
try
{
using (EmptyMVCApplicationEntities objConnection = new EmptyMVCApplicationEntities())
{
ObjectParameter objIErrorCode = new ObjectParameter("ErrorCode", typeof(Int32));
ObjectParameter objBFlag = new ObjectParameter("bFlg", typeof(bool));
objConnection.Check_User_Exists(User_Email, objBFlag, objIErrorCode);
if (Convert.ToBoolean(objBFlag.Value) != true)
{
return Json(new { Success = "false", Message = "Email exists" }, JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { Success = "True", Message = "Email not exists" }, JsonRequestBehavior.AllowGet);
}
}
}
catch (Exception Ex)
{
}
}
脚本
$("#User_Email").blur(function () {
if ($(this).val() != "") {
$.ajax({
url: "/User/VerifyUserEmail?User_Email=" + $("#User_Email").val(),
success: function (result) {
try {
var jsonIssueObj = $.parseJSON(result).Data;
} catch (e) { alert(e); }
if (!jsonIssueObj.Success) {
var errorMsg = jsonIssueObj.Message;
$('#msg').html(errorMsg);
$('#msg').show();
}
else {
var errorMsg = null;
$('#msg').html(errorMsg);
$('#msg').hide();
}
}
});
}
return false;
});
我得到以下错误:
SyntaxError:JSON.parse:JSON数据的第1行第2列出现意外字符
另外,如果我想要对象中的成功和消息,如何在控制器actionresult中将对象作为json传递。
您将返回具有2个属性( Success
和Message
json(不需要parseJSON
)。 要访问它们
success: function (result) {
var success = result.Success;
var message = result.Message;
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.