首頁 > web前端 > js教程 > 主體

ajax傳遞多個參數的實作程式碼

亚连
發布: 2018-05-24 09:44:48
原創
2183 人瀏覽過

這篇文章主要為大家詳細介紹了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訪問遇到Session失效的問題

ajax內部值外部呼叫不了的原因及解決方法

以上是ajax傳遞多個參數的實作程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!