>  기사  >  웹 프론트엔드  >  여러 매개변수를 전달하기 위한 Ajax 구현 코드

여러 매개변수를 전달하기 위한 Ajax 구현 코드

亚连
亚连원래의
2018-05-24 09:44:482180검색

이 글에서는 주로 여러 매개변수를 전달하는 ajax 구현 코드를 자세히 소개합니다. 간단하고 실용적이므로 관심 있는 친구가 참고할 수 있습니다.

이 글의 예제는 모든 사람에게 여러 매개변수를 전달하는 ajax의 특정 코드를 공유합니다. 참고로 구체적인 내용은 다음과 같습니다

<html >
<head>
  <title></title>
  <script src="js/Jquery1.7.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {


      $(&#39;#Button1&#39;).click(function () {
        var username = $(&#39;#txtUserName&#39;).val();
        var pwd = $(&#39;#txtPwd&#39;).val();
        $.ajax({
          type: "post",
          contentType: "application/json",
          url: "WebService1.asmx/Login",
          data: "{username:&#39;" + username + "&#39;,pwd:&#39;" + pwd + "&#39;}",
          success: function (bukeyi) {
            if (bukeyi.d == &#39;true&#39;) {
              window.location = &#39;HTMLPage1.htm&#39;;
            }
            else {
              $(&#39;#pinfo&#39;).text("用户名或密码错误");
            }
          }
        })
      })
    })
  </script>
</head>
<body>
用户名<input id="txtUserName" type="text" /><br />
密码<input id="txtPwd" type="text" /><br />
  <input id="Button1" type="button" value="登录" /><br />
  <p id="pinfo"></p>
</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"; }


    }
  }
}

위 내용은 제가 모두를 위해 정리한 내용이니 앞으로 모든 분들께 도움이 되었으면 좋겠습니다.

관련 기사:

Ajax 기술을 사용하여 제품 수량 및 총 가격 예제 코드를 부분적으로 새로 고침

Ajax 액세스 발생 시 세션 실패 문제를 완벽하게 해결

Ajax 내부 값을 사용하는 이유 ​​외부에서 호출할 수 없으며 솔루션

위 내용은 여러 매개변수를 전달하기 위한 Ajax 구현 코드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.