Use Ajax Success Handler to return JSON object

Discussion in 'JavaScript Forum' started by JessiOyolalf, Apr 9, 2013.

  1. JessiOyolalf

    JessiOyolalf New Member

    I am using an Ajax command to query data from a local server and I need to return a JSON object via the success handler.My Ajax command looks like this:\[code\]var json = $.ajax({ url: 'http://localhost:9200/wcs/routes/_search', type: 'POST', data: JSON.stringify({ "query": { "match_all": {} } }), dataType: 'json', async: false});\[/code\]I'd like to return the JSON document in the variable that I already have assigned: \[code\]json\[/code\]Could I do something like this in the command? (I know this isn't correct code):\[code\]success: return(json);});\[/code\]

Share This Page