用jQuery调用其他项目的WebService
实现登录验证功能
html输入用户名密码:
代码
| Login ID: | |
| Login Password: | |
| | |
Jquery引用和登录事件
代码
<script src="js/<a%20style=" color: text-decoration:underline title="jquery" href="https://www.php.cn/zt/15736.html" target="_blank">jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript"> <br>$(document).ready(function() <br>{ <br> $('#btnSignin').click <br> (function() <br> { <br> $.<a style="color:#f60; text-decoration:underline;" title= "ajax" href="https://www.php.cn/zt/15849.html" target="_blank">ajax <br> ( <br> { <br> type: "POST", <br> contentType: "application/json", <br> url: serviceURL+"/UserLogin", <br> data: "{UserLoginID:'"+$('#txtLoginID').val()+"',UserLoginPW:'"+$('#txtLoginPW').val()+"'}", <br> dataType: 'json', <br> success: function(result) <br> { <br> var user = eval(result.d); <br> location.href = "Welcome.aspx?userID="+user.UserID <br> }, <br> error: function(result, status) <br> { <br> if(status == 'timeout') <br> { <br> alert("The request timed out, please resubmit"); <br> } <br> else <br> { <br> if(result.responseText !="") <br> { <br> eval("exception = "+result.responseText); <br> alert(exception.Message); <br> } <br> } <br> } <br> } <br> ); <br> } <br> ); <br> }); <br> <br> $(document).ready(function() <br>{ <br> $('#btnSignup').click <br> (function() <br> { <br> location.href = "Signup/Signup.aspx"; <br> }) <br> }); <br></script>
serviceURL类似:var serviceURL = "http://localhost:1742/SoldierServices.asmx";
WebService代码:
代码
///
/// Summary description for SoldierServices
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class SoldierServices : System.Web.Services.WebService
{
[WebMethod]
public User UserLogin(string UserLoginID, string UserLoginPW)
{
LoginBusiness lb = new LoginBusiness();
return lb.UserLogin(UserLoginID, UserLoginPW);
}
[WebMethod]
public User GetUserInfo(string UserID)
{
LoginBusiness lb = new LoginBusiness();
return lb.GetUserInfo(UserID);
}
}
注意:[System.Web.Script.Services.ScriptService]默认是注释的,要把注释去掉











