溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

ajax中怎么傳遞多個(gè)參數(shù)

發(fā)布時(shí)間:2021-08-07 17:10:53 來(lái)源:億速云 閱讀:238 作者:Leah 欄目:web開(kāi)發(fā)

今天就跟大家聊聊有關(guān)ajax中怎么傳遞多個(gè)參數(shù),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

具體內(nèi)容如下

<html >
<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("用戶(hù)名或密碼錯(cuò)誤");
            }
          }
        })
      })
    })
  </script>
</head>
<body>
用戶(hù)名<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 的摘要說(shuō)明
  /// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  // 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。
  [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 "用戶(hù)名已被占用,請(qǐng)選擇其他";
      }
      else
      {
        return "可以使用,請(qǐng)繼續(xù)";
      }
    }


    [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"; }


    }
  }
}

看完上述內(nèi)容,你們對(duì)ajax中怎么傳遞多個(gè)參數(shù)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI