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>
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}"; }
$.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("可能服务器忙没有返回数据,请重试"); } });
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.