本文實例講述了jQuery調用WebMethod(PageMethod) NET2.0的方法。分享給大家供大家參考,具體如下:
首先必須在WebConfig下的system.web節(jié)點加入此配置信息
<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}";//我測試發(fā)現(xiàn),客戶段在接收數據的時候,會多了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("可能服務器忙沒有返回數據,請重試"); }});
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery遍歷算法與技巧總結》、《jQuery表格(table)操作技巧匯總》、《jQuery拖拽特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答