日期:2014-05-17 浏览次数:20641 次
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.Web.Script.Services; using System.Collections.Generic; namespace WebApplication1.App_Code { /// <summary> /// WebService1 的摘要说明 /// </summary> [WebService(Namespace = "http://www.hodoja.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { public WebService1() { } [WebMethod(EnableSession=true)] public List<Model.UserInfo> GetAll() { return new BLL.UserManager().GetAll(); } [WebMethod(EnableSession = true)] public Model.UserInfo LoginUser(string uname, string upwd) { return new BLL.UserManager().LoginUser(uname,upwd); } } }
function LoginUser() { var uname = document.getElementById("txtUname").value; var upwd = document.getElementById("txtUpwd").value; WebService1.LoginUser(uname,upwd,WebServiceSucceededMethod,WebServiceFailedMethod,LoginUserCallBack) } function LoginUserCallBack(result) { if(result !=null) { alert("成功"); } else alert("失败"); } //WebService调用成功时回调的函数 function WebServiceSucceededMethod(result, callback) { try{ if (callback != null) callback(result); } catch(err){ if (top.debug) { alert('错误:'+err.message) } } } //WebService调用失败时回调的函数 function WebServiceFailedMethod(result, callback) { try{ if (callback != null) { callback(result); } else { alert('网络错误,请稍候再试!'); } } catch(err){ if (top.debug) { alert('错误:'+err.message) } else { alert('网络错误,请稍候再试!'); } } }