zoukankan      html  css  js  c++  java
  • 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格式
    ?>

  • 相关阅读:
    在sql server中怎样获得正在执行的Sql查询
    在windows中使用VMWare安装Mac OS 10.7
    Scrspy 命令
    Windows Service 小品
    线程同步(一)
    线程基础必知必会(二)
    线程基础必知必会(一)
    准备工作与简介
    Python 正则表达式急速入门
    SQL Server 每日一题--每月销售额
  • 原文地址:https://www.cnblogs.com/Smina/p/7208906.html
Copyright © 2011-2022 走看看