"ajax"怎么传递多个数值?

JavaScript027

"ajax"怎么传递多个数值?,第1张

jquery 的ajax 向后台传递多个数值时可按一下方法操作。

<!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("用户名或密码错误")

}

}

})

}) 

}) 

</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> 

前台指定传的参数

$("#Query").click(function () {

var id = document.getElementById("txtId").value

$.ajax({

type: "POST",

url: "EndTree.aspx?Op_Type=Query",

data: { txtId: id },

success: function (data) {

alert(data.id)

}

})

})

$("#delete").click(function () {

var id = document.getElementById("txtId").value

$.ajax({

type: "post",

url: "EndTree.aspx?Op_type=Delete",

async: false,

data: { txtId: id },

success: function (data) {

getTree()

if (data.toString() != "error") {

{ alert("删除成功!")}

}

}

})

})

后台进行 if (Request["Req_Type"] == "QueryMessage")

{ 你的方法;

}