How do I turn this…
{
'name': 'John',
'surname': 'Smith'
}
…into this?
name=John&surname=Smith
I’m trying to send JSON to a server via AJAX
thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Gernerically (i.e. without any JS framework)…
As people in comments already noted, this would work for flat, non-nested objects only. For advanced uses, I strongly recommend doing an HTTP post operation and sending the object unmodified as a JSON string.
All JS libraries provide a way to transform an object to JSON, and there are other ways to serialize an object, like Douglas Crockford’s own implementation at http://json.org/js.html.