首页 > 代码库 > jQuery ajax如何传多个值到后台页面,举例:
jQuery ajax如何传多个值到后台页面,举例:
一、js代码
<script type="text/JavaScript">
$("#save_change_<{$aff.Id}>").click(function(){
//从模态框中取值,并通过ajax传到后台
var account = document.getElementById("change_account_<{$aff.Id}>").value;
var password = document.getElementById("change_password_<{$aff.Id}>").value;
var transactionCrawled = document.getElementById("change_transactionCrawled_<{$aff.Id}>").value;
$.ajax({
type: "POST",
url: "b_aff_aff_change.php",
dataType: "json", //当在前台页面获取后台的msg.account和msg.password是,不标明datatype:"json",是取不到值的!!!
data: "account="+account+"&id=<{$aff.Id}>&password="+password+"&transactionCrawled="+transactionCrawled, //跟url get传参类似,多个值直接加&,变量用+进行连接
success: function(msg){
//通过js改变当前页的td值
document.getElementById("account_<{$aff.Id}>").innerHTML = msg.account;
document.getElementById("password_<{$aff.Id}>").innerHTML = msg.password;
document.getElementById("transactionCrawled_<{$aff.Id}>").innerHTML = msg.transactionCrawled.toUpperCase();
}
});
});
</script>
二、后台页面b_aff_aff_change.PHP
<?php
echo json_encode($_POST); //与ajax中的datatype:"json"相对应,必须先将$_POST数组转换成json格式
?>
jQuery ajax如何传多个值到后台页面,举例: