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");
    }
});

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...

2 Answers 2

4

Create a JSON string with:

JSON.stringify({ json: tdata });

and then convert it to a PHP array with:

json_decode($data);
Sign up to request clarification or add additional context in comments.

Comments

2

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

data: JSON.stringify(tdata)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.