2015-01-10 113 views
0

我必須發送整數數組和字符串值與PHP的Ajax。 如何做到這一點,以及如何獲得這些值在PHP端?ajax後整數數組和字符串

// values to be send 
var nums = [1,2,3,4]; 
var method = "delete"; 

$.ajax({ 
    url: "ajaxcalls.php", 
    type: "GET", 
    dataType: "json", 
    data: ???, 
    contentType: 'application/json; charset=utf-8',  
}); 

// ajaxcalls.php 
<?php 
    ??? 
?> 

回答

2

只需將對象中的數據傳遞給$.ajax,jQuery就會爲您序列化數據。
在PHP中,您可以簡單地通過$ _GET超級全局檢索數據。

// values to be send 
var nums = [1,2,3,4]; 
var method = "delete"; 

$.ajax({ 
    url: "ajaxcalls.php", 
    type: "GET", 
    data: {"nums": nums, "method": method} 

}); 
<?php 
    $numArray = $_GET['nums']; 
    $method = $_GET['method'];