0

A quick question. I need to submit an array of object to the server as POST, but not an ajax request. I build the data through javascript, and not part of a form. I could think about an option, by creating a mock form with a submit button, and send the data as json. IS there a better way. Is there a native jQuery JSON encoder available? or is there a better way. I see serialize interface, but it may be difficult parse the string at the server, JSON is easier.

thanks,

bsr.

2 Answers 2

1

You can use JSON.stringify(arrayObject) to convert the array to JSON.

Another alternative, if you're building a mock form anyway, is to build your array using a number of <input type="hidden"/> fields with the same name.

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

2 Comments

Yup -- this is the approach I would go with, and then you should be able to json_decode it php side
thanks .. I didn't know that latest browsers has native JSON support.. robertnyman.com/javascript/javascript-native-json.html dbj.org/dbj/?p=470
0

An "ajax request" IS, in almost all implementations you are likely to encounter, a POST (or GET) request.

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.