views:

80

answers:

2

I used JQuery.serializeArray() on a form to create an array of objects on a GreaseMonkey application:

[
  {
    name: a
    value: 1
  },
  {
    name: b
    value: 2
  },
  {
    name: c
    value: 3
  },
  {
    name: d
    value: 4
  },
  {
    name: e
    value: 5
  }
]

I need to use GM_xmlhttpRequest to serve these fields back to a server side application. What is the best way to return these fields?

Thanks in advance,

D

A: 

I think I found the answer...

I need to use

JSON.stringify(obj)

to turn my serialized fields into a json string. Then I should be able to serve that string to the server as one of the data arguments in a GM_xmlhttpRequest POST request.

DKinzer
+1  A: 

JSON.stringify(obj) is the way to do it, but it is NOT cross-browser.

take look at this http://www.sitepoint.com/blogs/2009/08/19/javascript-json-serialization/#

naugtur
Thank you! That was a very informative article.
DKinzer