Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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");
    }
});

The above is working just fine but I would like to pass the array as a whole if that is possible like data: { tdata: tdata } as opposed to only passing the id. Is this possible to do or is there an alternative? I have not yet been able to get the whole array into PHP is some form I can read...

Thanks in advance...

share|improve this question

2 Answers

up vote 4 down vote accepted

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

data: JSON.stringify(tdata)
share|improve this answer

Create a JSON string with:

JSON.stringify({ json: tdata });

and then convert it to a PHP array with:

json_decode($data);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.