Understanding Response Data

When you send an AJAX request to the server, the server responds with response data. There are four main types of response that you will be working. These response data types are script, text, JSON, and XML/HTML.

In JavaScript, the response data is available in the response and responseText attributes of the XMLHttpRequest object once the request completes. In jQuery, the response data is passed as the first parameter to the AJAX handler function you define.

The script and text are handled pretty simply by the .load() and .getScript() methods. JSON and XML/HTML can be a bit more complex.

Using .getScript() to Load JavaScript Using AJAX

$.getScript("scripts/ajax/newLibray.js",   function(script, ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.