Send more than one JSON file in a single AJAX request

Asked

Viewed 229 times

2

I’m requesting two JSON files by Jquery’s getJSON function. I’m trying to send them through AJAX but I’m not getting through. I did the following:

var data = '[{"agents": '+agents +', "projects":' + projects + ', "spaces": ' +spaces+', "events":' + events +'}]';
var data_json = JSON.parse(data);

Where Agents, Projects, Spaces and Events were received through getJSON. The problem occurs in the call of the JSON.parse() function. How do I send all the JSON variables in a single request?

  • You can show the contents of these variables?

  • 3

    And why not var data_json = [{agents: agents, projects: projects, spaces: spaces, events: events}];? This is actually just an object, nor did it need to be array.

1 answer

1


If the data comes from getJson they are not strings;

var data = [{"agents":agents, "projects":projects, "spaces":spaces, "events": events}];

Leave so and send normally by ajax request.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.