当前位置: 移动技术网 > IT编程>脚本编程>Ajax > ajax传递多个参数具体实现

ajax传递多个参数具体实现

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="js/jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#button1').click(function () {
var username = $('#txtusername').val();
var pwd = $('#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>
用户名<input id="txtusername" type="text" /><br />
密码<input id="txtpwd" type="text" /><br />
<input id="button1" type="button" value="登录" /><br />
<div id="divinfo"></div>
</body>
</html>

------webservice1.asmx----
复制代码 代码如下:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.services;
namespace ajax11
{
/// <summary>
/// webservice1 的摘要说明
/// </summary>
[webservice(namespace = "http://tempuri.org/")]
[webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]
[system.componentmodel.toolboxitem(false)]
// 若要允许使用 asp.net ajax 从脚本中调用此 web 服务,请取消对下行的注释。
[system.web.script.services.scriptservice]
public class webservice1 : system.web.services.webservice
{
[webmethod]
public string helloworld()
{
return "hello world";
}
[webmethod]
public string validateuser(string username)
{
if (username == "onlifes")
{
return "用户名已被占用,请选择其他";
}
else
{
return "可以使用,请继续";
}
}
[webmethod]
public string getdate()
{
return datetime.now.tostring("yyyy-mm-dd hh:mm:ss");
}
[webmethod]
public string login(string username, string pwd)
{
if (username == "admin" && pwd == "888888")
{
return "true";
}
else
{ return "false"; }
}
}
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网