Passing Multiple Json Objects as data using jQuery's $.ajax()

后端 未结 5 1355
醉话见心
醉话见心 2020-12-16 23:19

I am POSTing data to an MVC controller and I\'m attempting to maintain state as well for optimistic concurrency. I\'m currently posting back a JSON request, but would be op

5条回答
  •  悲哀的现实
    2020-12-17 00:18

    As far as I know, there is no way to send back two completely different JSON objects that aren't children of a single parent JSON object and have jQuery decode it for you using the .ajax() method. You could, I suppose, reply with two JSON objects as strings and then use an external JSON library to evaluate the strings into a Javascript Object.

    Does that answer your question?

    Ooops: You're asking about posting two distinct JSON objects to your controller from jquery..., right? My bad... Yeah, you can do that... Just change this line:

    data: $.toJSON(data),
    

    to:

    data: { json_1:$.toJSON(data_1), json_2:$.toJSON(data_2) },
    

    Sorry about the mix-up.

提交回复
热议问题