Grant Collins
Grant Collins

Reputation: 1791

posting an array of json using dojo

Hi I am trying to post an array of javascript objects back to the server, using dojo.

I have an array of data that is like appears like this:

var elements = [
  myobj = {id:"1", name:"myname", title:"mytitle"},
  myobj = {id:"2", name:"myname2", title:"mytitle2"}
] 

I want to post this as a json string back to the server to be handled by a PHP script. However dojo.toJson will only seralise an individual object.

How can I convert the entire array of objects into a json string that can be posted to the backend for processing?

many thanks

Upvotes: 1

Views: 1913

Answers (1)

Eugene Lazutkin
Eugene Lazutkin

Reputation: 43956

You are misinformed: dojo.toJson() handles arrays without a problem. I just plugged in your elements and that's what I've got:

[{"id":"1","name":"myname","title":"mytitle"},{"id":"2","name":"myname2","title":"mytitle2"}]

Looks okay to me.

But maybe I misunderstood something? Please post a sample proving your point.

Upvotes: 5

Related Questions