Ajax passes multiple parameters to implement _ajax correlation

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 ("User name or password error");
}
}
})
})
})
</script>
<body>
User name <input id= "txtUserName" type= "text"/><br/>
Password <input id= "txtpwd" type= "text"/><br/>
<input id= "Button1" type= "button" value= "Login"/><br/>
<div id= "Divinfo" ></div>
</body>

------webservice1.asmx----
Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Namespace ajax11
{
<summary>
Summary description of WebService1
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[System.ComponentModel.ToolboxItem (False)]
To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink.
[System.Web.Script.Services.ScriptService]
public class WebService1:System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld ()
{
Return to "Hello World";
}
[WebMethod]
public string ValidateUser (string username)
{
if (username = = "Onlifes")
{
Return "User name has been occupied, please select another";
}
Else
{
Return "can be used, please continue";
}
}
[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 ';}
}
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.