jQuery ajax如何傳多個值到後台頁面,舉例:

來源:互聯網
上載者:User

標籤:data   code   模態框   url   前台   type   enc   rip   led   

 

一、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如何傳多個值到後台頁面,舉例:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.