ajax傳遞多個(gè)參數(shù)具體實(shí)現(xiàn)
更新時(shí)間:2013年05月21日 17:32:42 作者:
在使用ajax過(guò)程中,傳遞參數(shù)是在所難免的尤其在特殊情況下傳遞多個(gè)參數(shù),下面與大家分享下具體的是實(shí)現(xiàn)方法,感興趣的朋友可以參考下哈
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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----
復(fù)制代碼 代碼如下:
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"; }
}
}
}
您可能感興趣的文章:
- ajax上傳時(shí)參數(shù)提交不更新等相關(guān)問(wèn)題
- 關(guān)于jquery ajax 調(diào)用帶參數(shù)的webservice返回XML數(shù)據(jù)一個(gè)小細(xì)節(jié)
- Jquery ajax傳遞復(fù)雜參數(shù)給WebService的實(shí)現(xiàn)代碼
- 真正的JQuery.ajax傳遞中文參數(shù)的解決方法
- JQuery.ajax傳遞中文參數(shù)的解決方法 推薦
- jQuery Tips 為AJAX回調(diào)函數(shù)傳遞額外參數(shù)的方法
- ajax回調(diào)函數(shù)參數(shù)傳遞正確方法
- Extjs ajax同步請(qǐng)求時(shí)post方式參數(shù)發(fā)送方式
- 傳遞參數(shù)的標(biāo)準(zhǔn)方法(jQuery.ajax)
- ajax傳遞一個(gè)參數(shù)具體實(shí)現(xiàn)
相關(guān)文章
[asp]天楓AJAX百度音樂(lè)即時(shí)聽(tīng)附下載
[asp]天楓AJAX百度音樂(lè)即時(shí)聽(tīng)附下載...2007-09-09
[ASP.NET Ajax] ECMAScript基礎(chǔ)類以及Asp.net Ajax對(duì)類<Object&a
[ASP.NET Ajax] ECMAScript基礎(chǔ)類以及Asp.net Ajax對(duì)類<Object>的擴(kuò)展...2007-01-01
有史以來(lái)最簡(jiǎn)單的AJAX回調(diào)庫(kù)
很多時(shí)候我們只要用到一些簡(jiǎn)單的Ajax功能,提供一些簡(jiǎn)單的回調(diào)而不需要很花哨的東西。然而現(xiàn)有的很多Ajax庫(kù)都很大,雖然功能很多但是我們很多時(shí)候根本就不需要用到他們,我就遇到過(guò)那樣的經(jīng)歷,所以我想弄一個(gè)很簡(jiǎn)單的Ajax回調(diào)函數(shù)來(lái)搞定。2008-10-10
Ajax 無(wú)刷新在注冊(cè)用戶名時(shí)的應(yīng)用的代碼
Ajax 無(wú)刷新在注冊(cè)用戶名時(shí)的應(yīng)用的代碼...2007-04-04
ajax請(qǐng)求post和get的區(qū)別以及get post的選擇
這篇文章主要介紹了ajax請(qǐng)求post和get的區(qū)別以及get post的選擇,需要的朋友可以參考下2014-06-06
.NET2.0環(huán)境下的Ajax選型和應(yīng)用(提供Demo源碼下載)
.NET2.0環(huán)境下的Ajax選型和應(yīng)用(提供Demo源碼下載)...2007-05-05

