Parsing AJAX Responses with JavaScript and the innerHTML Property
If you work with AJAX and have ever wondered which approach is best to use when parsing the responses triggered by a web server after performing an HTTP request, this article series is for you. Composed of three parts, it will lay out your options and the most efficient approaches. This article, the first part of the series, focuses on the "responseText" property and the "innerHTML" property.
Parsing AJAX Responses with JavaScript and the innerHTML Property - The full source code of the sample AJAX application (Page 4 of 4 )
As I stated in the earlier section, here is the entire source code of this sample AJAX application. It uses the "innerHTML" JavaScript property to parse user data coming from the sample "Users" MySQL database table that you saw previously:
(definition of ajax_sample.htm file)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
As usual with my articles on web development, you're completely free to tweak all the code samples shown in this tutorial. In this way you can become comfortable with using the non-standard "innerHTML" property to parse server responses that are sent as plain text.
Final thoughts
In this first article of the series you hopefully learned how to use the "innerHTML" JavaScript property to parse different web server responses within AJAX-based applications. Nonetheless, the down side to using this property is that it's not considered standard by the W3 Consortium.
Therefore, in the next part of the series, I'll show you how to utilize the functionality of the DOM (instead of the previous "innerHTML" property) to parse plain text web server responses from inside a concrete AJAX application.
Now that you've been warned, I hope to see you there!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.