gpt4 book ai didi

jquery - 如何从Jquery调用asp.net方法

转载 作者:行者123 更新时间:2023-12-01 01:24:23 25 4
gpt4 key购买 nike

大家好,我有一个网页,它使用 Jquery 将数据从对话框发送到使用 $.ajax 的 asp.net 方法,但它总是给我一个 404 错误网页未找到。

Ajax 将此链接提供给请求“Localhost:1395/Login.aspx/sendEmail”(使用 firebug 获得),但发送电子邮件是应在 Login.aspx 页面中调用的方法。

这是 JQuery 代码:

   $.ajax({
type: 'POST',
url: 'Login.aspx/sendEmail',
data: '{"strEmail":"' + $('#hplForgotDialog').find('input[id$=txtForgotEmail]').val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json"
});

任何有关此问题的帮助都将非常感激。

编辑:为了进一步演示该错误,我将添加一个描述 URL 错误的图像以使其尝试连接。

enter image description here

最佳答案

我的猜测是,您需要设置路由。你可以在这里读到它: http://msdn.microsoft.com/en-us/library/cc668201.ASPX

基本上,如果我是对的(我可能不是),您的路由找不到正确的操作(或在非 MVC 场景中调用的任何操作)。在 Web 表单中,您必须在 Global.asax 文件的 Application_Start 事件处理程序中设置自定义路由。

类似这样的事情:

protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("",
"Category/{action}/{categoryName}",
"~/categoriespage.aspx");
}

这样,您就可以告诉应用程序如何理解 URL 及其参数。这是url/Category/param1/param2,所有符合这个模式的东西,都会被定向到categoriespage.aspx页面,可以用参数做任何它想做的事情(例如调用正确的方法)。

关于jquery - 如何从Jquery调用asp.net方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18340686/

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