How to POST an array of objects with $.ajax

Base on earlier post which I talk about JSON. Here is the application part. Imagine you have an array of objects from client side need post back to server side for processing. JSON.stringify can do the trick of sending the array back to server side. Remember to put it before sending it.

Sample Illustration Below:

objs = [
   {name: abc, age: 20, id: 123},
   {name: def, age: 23, id: 456, pet: dog},
   {name: efg, age: 30, id: 678, pet: {id: animal1, animal: cat, color: black}}
]
$.ajax({
    url: postbackUrl,
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify(objs);
});

3 thoughts on “How to POST an array of objects with $.ajax

  1. Fantastic blog! Do you have any helpful hints for aspiring writers? I’m hoping to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any suggestions? Thanks!

    1. Linwood Cokins. Thank you for your question.
      I would recommend you to have your own personal blog with own hosting and domain name. This can reduce problems in the future e.g. when there are lots of traffic, you may consider monetize you blog but free WordPress platform does not provide such function. Another case free WordPress platform does allow blogger to put Google Adsense on to the blog. You might consider this point.

      I have a blog on free WordPress platform. You may visit my blog here: https://waiseekweng.wordpress.com/

      Hope I did answer your question. If you have questions/problems while setting up your own blog, just let me know and I can help you. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

×