ajax傳遞多個(gè)參數(shù)的實(shí)現(xiàn)代碼
本文實(shí)例為大家分享了ajax傳遞多個(gè)參數(shù)的具體代碼,供大家參考,具體內(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("用戶名或密碼錯(cuò)誤"); } } }) }) }) </script> </head> <body> 用戶名<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 "用戶名已被占用,請(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"; } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- 傳遞參數(shù)的標(biāo)準(zhǔn)方法(jQuery.ajax)
- ajax回調(diào)函數(shù)參數(shù)傳遞正確方法
- jQuery Tips 為AJAX回調(diào)函數(shù)傳遞額外參數(shù)的方法
- JQuery.ajax傳遞中文參數(shù)的解決方法 推薦
- 真正的JQuery.ajax傳遞中文參數(shù)的解決方法
- Jquery ajax傳遞復(fù)雜參數(shù)給WebService的實(shí)現(xiàn)代碼
- jquery ajax 向后臺(tái)傳遞數(shù)組參數(shù)示例
- jsp中利用jquery+ajax在前后臺(tái)之間傳遞json格式參數(shù)
- jquery ajax傳遞中文參數(shù)亂碼問(wèn)題及解決方法說(shuō)明
- Ajax傳遞中文參數(shù)到后臺(tái)亂碼的有效解決方法
相關(guān)文章
ajax響應(yīng)json字符串和json數(shù)組的實(shí)例(詳解)
下面小編就為大家?guī)?lái)一篇ajax響應(yīng)json字符串和json數(shù)組的實(shí)例(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-02-02Ajax配合Spring實(shí)現(xiàn)文件上傳功能代碼
最近在開(kāi)發(fā)一個(gè)可以上傳圖片到服務(wù)器的web表面頁(yè)面,下面給大家分享需求和實(shí)現(xiàn)思路,需要的的朋友參考下吧2017-05-05AJAX實(shí)現(xiàn)指定部分頁(yè)面刷新效果
這篇文章主要為大家詳細(xì)介紹了AJAX實(shí)現(xiàn)指定部分頁(yè)面刷新效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10讓ajax更加友好的實(shí)現(xiàn)方法(實(shí)時(shí)顯示后臺(tái)處理進(jìn)度。)
我們能否讓ajax更加友好點(diǎn),實(shí)時(shí)顯示服務(wù)器處理的進(jìn)度了?這在一些長(zhǎng)時(shí)間的請(qǐng)求中尤其重要,比如上傳文件、發(fā)送郵件、批量處理數(shù)據(jù)。2010-06-06Echarts教程之通過(guò)Ajax實(shí)現(xiàn)動(dòng)態(tài)加載折線圖的方法
這篇文章主要介紹了Echarts教程之通過(guò)Ajax實(shí)現(xiàn)動(dòng)態(tài)加載折線圖的方法,需要的朋友可以參考下2018-04-04