1
tdata = new Array();  
tdata['id'] = "helloid";  
tdata['name'] = "helloname";  
tdata['location'] = "hellolocation";  
tdata['about'] = "helloabout";  
tdata['company'] = "hellocompany";  
tdata['website'] = "hellowebsite";  

$.ajax({
    url: 'export.setsession.php',
        data: { tdata: tdata.id 
    },
    type: 'post',
    success: function (output) {
        //$(location).attr('href', 'index.php');
        alert("girdsposted");
    }
});

以上工作正常,但如果可能的话,我想将数组作为一个整体传递,例如 data: { tdata: tdata } 而不是仅传递 id。这是可能的还是有替代方案?我还不能将整个数组放入 PHP 中,这是我可以阅读的某种形式......

提前致谢...

4

2 回答 2

4

使用以下命令创建 JSON 字符串:

JSON.stringify({ json: tdata });

然后将其转换为 PHP 数组:

json_decode($data);
于 2013-02-18T01:56:31.427 回答
2

Have you considered using the JSON.stringify() method, which will transform your tdata element into a JSON string :

data: JSON.stringify(tdata)
于 2013-02-18T01:59:09.950 回答