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

  • 相关阅读:
    DGL学习(六): GCN实现
    DGL学习(五): DGL构建异质图
    DGL学习(四): 图分类教程
    LuoGuP2495:[SDOI2011]消耗战
    LuoGuP1121:环状最大两段子段和
    LuoGuP3177:[HAOI2015]树上染色
    LuoGuP2607:[ZJOI2008]骑士
    HDU4283:You Are the One
    LuoGuP4294:[WC2008]游览计划
    LuoGuP4127:[AHOI2009]同类分布
  • 原文地址:https://www.cnblogs.com/Smina/p/7208906.html
Copyright © 2011-2022 走看看