我想通過post請求將數組和其他變量從jQuery代碼傳遞到php,但我不知道如何在同一時間傳遞數組和變量。同時將數組和變量從jquery傳遞到php
我試過這段代碼:
var new_location_name = "";
var new_location_id = "";
var old_location_name = [];
var selected_name = [];
var selected_id = [];
var user = '<?php echo $current_user ;?>';
$(document).ready(
$("#transfer").click(function(){
$.ajax({
type: "POST",
url: "update.php",
data: "username="+user+"&new_location_name="+new_location_name+"&new_location_id"+new_location_id+"&"+{ old_location_name : old_location_name }+"&"+{ selected_name : selected_name }+"&"+{ selected_id : selected_id },
});
return false;
});
});
感謝您的快速響應,如果我發送這樣的數組和變量,我需要在php文件的另一邊做什麼來獲取每個數組和每個變量的值? –
它們只是php函數的參數,然後您可以將它們作爲JSON訪問。 – Avitus