0

I am trying to post data to the action method in the postData section in jqGrid like this, but get an error, any ideas?

     postData: { species: function() 
                                    {
                                        return JSON.stringify($("form"));
                                    },

I can tell you that this format below does work but it is not JSON:

postData: { species: $("form").serialize() },
KeelRisk
  • 749
  • 1
  • 9
  • 27
  • actually, now that I look closer, I don't specifically see an error. However, it does not enter my action method eventhough I have a breakpoint. – KeelRisk Mar 11 '12 at 02:39
  • One thing to add...I don't know if it matters but when I type JSON.stringify I do not get any intelisense. Not sure if I'm supposed to or not. I did add the script reference to my main _layout page: – KeelRisk Mar 11 '12 at 02:57

1 Answers1

0

Probably you should use jQuery.serializeArray instead of jQuery.serialize:

postData: {
    species: function() {
        return JSON.stringify($("form").serializeArray());
    }
}

See also the answer for some more version of data conversion of the data returned from $("form").serializeArray() before calling of JSON.stringify.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798