gpt4 book ai didi

javascript - 外部 JavaScript 文件中的 AJAX 调用未到达 Controller 中的 ActionResult

转载 作者:行者123 更新时间:2023-11-30 15:29:55 25 4
gpt4 key购买 nike

我正在尝试检查数据库中是否存在电子邮件地址。我有一个外部 JavaScript 文件,我用它来调用我的 jQuery(以保持我的 View 干净)。也许是因为我在启用 SSL 的情况下运行? (我正在使用 https)

外部js文件中的函数:

function checkemail() {
var email = $("#email").val();
$.ajax({
url: "/Account/CheckEmailExists/",
data: JSON.stringify({ p: email }),
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data)
}
});
}

Controller 中的 Action :

public ActionResult CheckEmailExists(string p)
{
bool bEmailExists = false;

using (RBotEntities EF = new RBotEntities())
{
var query = (from U in EF.AspNetUsers
where U.Email == p
select U).FirstOrDefault();

if(query.Email != null)
{
bEmailExists = true;
}
else
{
bEmailExists = false;
}
}

return Json(bEmailExists, JsonRequestBehavior.AllowGet);
}

我似乎收到以下错误:

XML Parsing Error: no root element found Location: https://localhost:44347/Account/CheckEmailExists/ Line Number 1, Column 1:

我的理解是这个 ActionResult 不存在。但它确实如此吗?

是我做错了什么,还是无法通过外部 JavaScript 文件调用 ActionResult

最佳答案

试试这个

在 Controller 中

[httppost]
public ActionResult CheckEma.........

在 JS 中

function checkemail() {
var email = $("#email").val();
$.ajax({
url: "/Account/CheckEmailExists/",
data: { p: email },
type: "POST",
success: function (data) {
alert(data)
}
});
}

关于javascript - 外部 JavaScript 文件中的 AJAX 调用未到达 Controller 中的 ActionResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com