0

I've 1 object:

var myobject = {first: 1, second: {test: 90}, third: [10, 20]};

and I want to send it as JSON string via jQuery ajax.

How can I do it? (i test JSON.stringify(), but it doesn't work in IE)

Thanks.

4

2 Answers 2

1

If you specify your myobject as the data parameter to the jQuery .ajax() method, it will automatically convert it to a query string, which I believe is what you want.

e.g.

$.ajax({
    url: /* ... */,
    data: myobject,
    /* other settings/callbacks */
})

From the docs:

data

Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs.

Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to pass your object to the 'data' parameter of the ajax function -

$.ajax({
   type: "POST",
   url: "some.php",
   data: myobject ,
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

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.