jQueryAJAX调用WebService实现代码
代码 实现 调用 webservice JqueryAJAX
2023-06-13 09:14:17 时间
用jQuery调用其他项目的WebService
实现登录验证功能
html输入用户名密码:
代码
复制代码代码如下:
实现登录验证功能
html输入用户名密码:
代码
<tablestyle="width:400px">
<tr>
<tdstyle="width:200px"class="left">
LoginID:
</td>
<tdstyle="width:200px"class="left">
<inputid="txtLoginID"type="text"style="width:190px;"value=""/>
</td>
</tr>
<tr>
<tdstyle="width:200px"class="left">
LoginPassword:
</td>
<tdstyle="width:200px"class="left">
<inputid="txtLoginPW"type="password"style="width:190px;"value=""/>
</td>
</tr>
<tr>
<tdstyle="width:200px"class="center">
<inputid="btnSignin"value="Signin"class="button"readonly/>
</td>
<tdstyle="width:200px"class="center">
<inputid="btnSignup"value="Signup"class="button"readonly/>
</td>
</tr>
</table>
Jquery引用和登录事件
代码
<scriptsrc="js/jquery-1.4.2.min.js"type="text/javascript"></script>
<scripttype="text/javascript"language="javascript">
$(document).ready(function()
{
$("#btnSignin").click
(function()
{
$.ajax
(
{
type:"POST",
contentType:"application/json",
url:serviceURL+"/UserLogin",
data:"{UserLoginID:""+$("#txtLoginID").val()+"",UserLoginPW:""+$("#txtLoginPW").val()+""}",
dataType:"json",
success:function(result)
{
varuser=eval(result.d);
location.href="Welcome.aspx?userID="+user.UserID
},
error:function(result,status)
{
if(status=="timeout")
{
alert("Therequesttimedout,pleaseresubmit");
}
else
{
if(result.responseText!="")
{
eval("exception="+result.responseText);
alert(exception.Message);
}
}
}
}
);
}
);
});
$(document).ready(function()
{
$("#btnSignup").click
(function()
{
location.href="Signup/Signup.aspx";
})
});
</script>
serviceURL类似:varserviceURL="http://localhost:1742/SoldierServices.asmx";
WebService代码:
代码
///<summary>
///SummarydescriptionforSoldierServices
///</summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
//ToallowthisWebServicetobecalledfromscript,usingASP.NETAJAX,uncommentthefollowingline.
[System.Web.Script.Services.ScriptService]
publicclassSoldierServices:System.Web.Services.WebService
{
[WebMethod]
publicUserUserLogin(stringUserLoginID,stringUserLoginPW)
{
LoginBusinesslb=newLoginBusiness();
returnlb.UserLogin(UserLoginID,UserLoginPW);
}
[WebMethod]
publicUserGetUserInfo(stringUserID)
{
LoginBusinesslb=newLoginBusiness();
returnlb.GetUserInfo(UserID);
}
}
注意:[System.Web.Script.Services.ScriptService]默认是注释的,要把注释去掉
相关文章
- 湖仓一体电商项目(十六):业务实现之编写写入ODS层业务代码
- 一行代码教你实现登录鉴权
- 10 行 Python 代码,使用 OTP 实现对文件的加密解密
- 【Groovy】MOP 元对象协议与元编程 ( 方法委托 | 正常方法调用 | 方法委托实现 | 代码示例 )
- Rc-lang开发周记3 生成C++代码
- 实例使用Redis实现分页缓存功能(redis分页缓存代码)
- javascriptfullscreen全屏实现代码
- jQueryAJax调用asp.netwebservers的实现代码
- javascript下搜索子字符串的的实现代码(脚本之家修正版)
- 使用C#调用系统API实现内存注入的代码
- PHP验证码的实现代码
- php模板函数正则实现代码
- MySQL定时器开启、调用实现代码
- C#程序最小化到托盘图标操作步骤与实现代码
- 高仿网易新闻顶部滑动条效果实现代码
- js调用webservice中的方法实现思路及代码
- html中使用javascript调用本地程序(exe、doc等)实现代码
- jquery实现的一个导航滚动效果具体代码
- js调用父窗口的具体实现代码
- jquery实现多级下拉菜单的实例代码
- java实现约瑟夫环的实例代码
- php修改、增加xml结点属性的实现代码
- JavaScript调用ajax获取文本文件内容实现代码
- VB实现的倒计时类代码详解
- Ruby中用线程实现经典的生产者消费者问题代码实例
- asp实现检查ip地址是否为内网或者私有ip地址的代码分享