AJAX

Ways to return content through XMLHTTPRequest: plain text, JavaScript variables, JSON objects, and XML.

Gengns-Genesis / Wikimedia CommonsCC BY-SA 4.0

Ways to return content through XMLHTTPRequest: plain text, JavaScript variables, JSON objects, and XML.

Ways to return content through XMLHTTPRequest: plain text, JavaScript variables, JSON objects, and XML.

Returning content through XMLHTTPRequest

There are various ways you can return content through XMLHTTPRequest:

  • Plain text (XML.responseText)
  • Javascript variables (eval(XML.responseText))
  • JSON – Javascript objects (eval(XML.responseText))
  • XML (XML.responseText = XML)

Of these, plain text is the simplest, as all it requires is servicing a request with a simple plain text dump of data. The downside to this method is that it’s not always a clean way to return more than one variable.

Javascript variables are a nice way to return multiple variables through an XMLHTTPRequest call. Instead of dumping plain text, the server decorates the different returned variables with javascript variable declarations. On the client end, the XMLHTTPRequest callback function evals the server response and now has the variables set by the server available to it as native javascript variables.

One key part of this method however is remembering to escape the content in the javascript variable assignment.

The third way of passing back content through XMLHTTPRequest is XML, which despite the name of the function, is often the slowest and most difficult way due to difficulties parsing xml. However for highly structured content or when E4X becomes more standard, this might be the way to go.

Updated: 2026 Aug 19