$(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("用户名或密码错误");
}
}
})
})
})
用户名
密码
------webservice1.asmx----
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.services;
namespace ajax11
{
///
/// webservice1 的摘要说明
///
[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"; }
}
}
}