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格式
?>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值