June 2015
Intermediate to advanced
192 pages
4h 8m
English
Finally, it's time to see how to get the returned JSON from the server and use it. You'll do this by registering an event handler on $.ajax to receive the resulting JavaScript object, which jQuery helpfully deserializes from JSON for you.
To get the result from the AJAX request, we need to add an event handler to the jQuery XMLHttpRequest object's done event, as follows:
function doAjax() { $('#debug').html("loaded... executing."); var request = { call: "kf6gpe-7" }; $.ajax({ type: "POST", url: "/", data: JSON.stringify(request), dataType:"json", }) .fail(function() { $('#debug').html( $('#debug').html() + "<br/>failed"); }) .always(function() { $('#debug').html( $('#debug').html() + "<br/>complete"); ...Read now
Unlock full access