如何使用jquery GET方式请求调用asp.net方法
2009-12-04 20:36
686 查看
前台页面
后台页面代码Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace jquery_Learning
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
char method = Convert.ToChar(HttpContext.Current.Request.QueryString["m"]);
if (method.ToString() == null )
{
method = Convert.ToChar(HttpContext.Current.Request.Form["m"]);
}
HttpContext.Current.Request.ContentType = "text/plain";
switch (method)
{
case 'a':
HttpContext.Current.Response.Write("a");
break;
case 'b':
HttpContext.Current.Response.Write("b");
break;
}
Response.End();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Third.aspx.cs" Inherits="jquery_Learning.Third" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script src="JQUERY.JS" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $("#btn1").click(function(){ $.ajax({ type: "GET", url: "Default.aspx?m=b", success: function(msg) { alert(msg); } }); }); $("#btn2").click(function(){ $.ajax({ type:"POST", url:"Default.aspx?m=a", success:function(msg){ alert(msg); } }); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input id="btn1" type="button" value="GET" /><br /> <input id="btn2" type="button" value="POST" /> </div> </form> </body> </html>
后台页面代码Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace jquery_Learning
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
char method = Convert.ToChar(HttpContext.Current.Request.QueryString["m"]);
if (method.ToString() == null )
{
method = Convert.ToChar(HttpContext.Current.Request.Form["m"]);
}
HttpContext.Current.Request.ContentType = "text/plain";
switch (method)
{
case 'a':
HttpContext.Current.Response.Write("a");
break;
case 'b':
HttpContext.Current.Response.Write("b");
break;
}
Response.End();
}
}
}
相关文章推荐
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- asp.net 通过ajax方式调用webmethod方法使用自定义类传参及获取返回参数
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- asp.net 事务的处理,dts 的设置,asp.net三种事务处理方法,三层架构,微软企业库,动软生成器生成的代码下如何使用事务
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- Asp.net 2.0 中如何调用用户控件(UserControl)的相关方法或属性/如何传参等
- 使用ASP.NET AJAX 从脚本中调用Web 服务的应用方法
- 如何通过js跨域调用ASP.NET Web API (请问如何实现在javascript中通过http get的方式跨域调用ASP.NET Web API?)
- 在ASP.NET 4.0中使用.NET 2.0的请求验证行为方法(转)
- 第三部分 02 在ASP.NET AJAX应用程序中使用JavaScript异步调用Page的方法
- asp.net 前端使用jquery $post 方法调用webservice 部署到IIS时会无法使用的问题
- asp.net后台如何输出js脚本使用什么方法可以实现
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- MattPowell介绍了如何在服务器端使用异步Web方法,来创建高性能的 Microsoft ASP.NET Web 服务
- 如何:确定调用 ASP.NET 网页的方式 [转帖]
- ASP.NET AJAX 以及AJAXPRO使用客户端调用服务器端的方法--初学者学习
- ASP.NET中MVC使用AJAX调用JsonResult方法并返回自定义错误信息
- asp.net客户端调用服务器端方法——AjaxPro.2.dll的使用
- asp.net中ajax使用(客户端调用服务端方法)