如何调用从jQuery的asp.net方法 [英] how to call asp.net method from Jquery

查看:94
本文介绍了如何调用从jQuery的asp.net方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我有一个使用jQuery从对话框使用$阿贾克斯的asp.net方法发送的数据的网页,但它总是给我一个404错误网页没有找到。

Hi everyone I have a web page that is using Jquery to send the data from a dialog to the asp.net method using $.ajax, but it's always giving me a 404 error Web Page not found.

阿贾克斯是给这个链接的请求。本地主机:1395 /的Login.aspx / sendEmail(使用萤火虫获得),但发Email是应该在网页的Login.aspx被称为法

The Ajax is giving this link to the request "Localhost:1395/Login.aspx/sendEmail" (Obtained using firebug), but send Email is the method that should be called in the Login.aspx page.

这是JQuery的code:

This is the JQuery code:

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

这个问题的任何帮助将是一个真正的preciated。

Any help with this problem would be really apreciated.

编辑:证明错误的更多一点,我会添加一个图像描绘了URL错误魔域它会尝试连接

to demonstrate the error a little more I'll add an image depicting the URL error to witch it tries to connect.

推荐答案

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

My guess would be, you need to setup routing. You can read about it here: http://msdn.microsoft.com/en-us/library/cc668201.ASPX

基本上,如果我是正确的(我至极可能不是),你的路由没有找到正确的动作(或不管他们被称为在非MVC的情况)。在Web窗体,你必须在Global.asax文件设置的自定义路线,在Application_Start事件处理程序。

Basically, if I'm right (wich I might not be), your routing doesn't find the correct Actions (or whatever they are called in a non-MVC scenario). In Web Forms, you have to setup custom routes in the Global.asax file, in the Application_Start event handler.

事情是这样的:

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 /分类/参数1 /参数2,这个模式匹配的一切,将被引导到categoriespage.aspx页面,有什么可以做任何它想要的参数(调用例如正确的方法)。

With this, you tell the application how to understand URLs, and their parameters. This is the url /Category/param1/param2, everything that matches this pattern, will be directed to the categoriespage.aspx page, what can do whatever it wants with the parameters (call the correct method for example).

这篇关于如何调用从jQuery的asp.net方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆