ajax传递多个参数的实现代码
本文实例为大家分享了ajax传递多个参数的具体代码,供大家参考,具体内容如下
<html>
<head>
<title></title>
<scriptsrc="js/Jquery1.7.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$('#Button1').click(function(){
varusername=$('#txtUserName').val();
varpwd=$('#txtPwd').val();
$.ajax({
type:"post",
contentType:"application/json",
url:"WebService1.asmx/Login",
data:"{username:'"+username+"',pwd:'"+pwd+"'}",
success:function(bukeyi){
if(bukeyi.d=='true'){
window.location='HTMLPage1.htm';
}
else{
$('#divinfo').text("用户名或密码错误");
}
}
})
})
})
</script>
</head>
<body>
用户名<inputid="txtUserName"type="text"/><br/>
密码<inputid="txtPwd"type="text"/><br/>
<inputid="Button1"type="button"value="登录"/><br/>
<divid="divinfo"></div>
</body>
</html>
WebService1.asmx
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Services;
namespaceajax11
{
///<summary>
///WebService1的摘要说明
///</summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//若要允许使用ASP.NETAJAX从脚本中调用此Web服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
publicclassWebService1:System.Web.Services.WebService
{
[WebMethod]
publicstringHelloWorld()
{
return"HelloWorld";
}
[WebMethod]
publicstringValidateUser(stringusername)
{
if(username=="onlifes")
{
return"用户名已被占用,请选择其他";
}
else
{
return"可以使用,请继续";
}
}
[WebMethod]
publicstringGetDate()
{
returnDateTime.Now.ToString("yyyy-MM-ddhh:mm:ss");
}
[WebMethod]
publicstringLogin(stringusername,stringpwd)
{
if(username=="admin"&&pwd=="888888")
{
return"true";
}
else
{return"false";}
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助。