Home > Web Front-end > JS Tutorial > body text

jQuery calls WebMethod(PageMethod) NET2.0 method_jquery

WBOY
Release: 2016-05-16 15:05:26
Original
1466 people have browsed it

The example in this article describes how jQuery calls WebMethod (PageMethod) NET2.0. Share it with everyone for your reference, the details are as follows:

First, you must add this configuration information to the system.web node under WebConfig

<httpModules>
   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

Copy after login
ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
/// <summary>
/// 是否允许注册
/// </summary>
/// <param name="MemberLoginID"></param>
/// <returns></returns>
public static MemberInfo AllowRegist(string MemberLoginID)
{
    return new MemberInfo();//由于设置了返回类型是JSON,所以客户端的JQ能够识别
    // MemberInfoBLL mi = new MemberInfoBLL();
    //if (!mi.ExistMember(MemberLoginID))
      //return "{d:true}";//我测试发现,客户段在接收数据的时候,会多了2个双引号,导致转换JSON格式失败..郁闷
    //else
      //return "{d:false}";
}

Copy after login
$.ajax({
    cache:false,
    type: 'POST',
    contentType: 'application/json; charset=utf-8',
    data: "{'MemberLoginID':'" + $("#<%=MemberLoginID.ClientID %>").val() + "'}",
    dataType: 'json',
    url: 'Reg.aspx/getDate',
    success: function(result,x,y) {
      alert(result);
    },
    beforeSend:function (xhr) {
      xhr.setRequestHeader('If-Modified-Since', '0');
      //this; // 调用本次AJAX请求时传递的options参数
    },
    error: function(e) {
      debugger; //alert("可能服务器忙没有返回数据,请重试");
    }
});

Copy after login

Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery traversal algorithm and skills summary", "jQuery table (table) operation skills summary" , "Summary of jQuery drag effects and techniques", "Summary of jQuery extension techniques", "Summary of jQuery common classic special effects", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage summary"

I hope this article will be helpful to everyone in jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!