Brian began developing applications for the Internet in 1995, and has continued to architect, design and develop Internet software for the last 11 years, including projects for IHG, IBM, Brighthouse, and Cox Target Media (Valpak).

Here he shares his thoughts and opinions on Internet Software Architecture and Development, chronicles his current projects and areas of research, and give tips and tricks he discovers along the way.

Web 2.0



AJAX Returning HTML (change of opinion)

After further thought and consideration, I retract my statement that HTML should never be sent back to an AJAX request. There was a reason I made that statement, however I can’t fill you in on it yet (hint: I have to wait for a future software release). But, even with that reason, I have no issue with using HTML in an AJAX response. I wrongly applied a wise and fully correct architectural principle, which I will elaborate on in a future post, to the AJAX situation.

Hopefully at some point in the future, I can go into more detail on why I first wrongly concluded that this should never be done. Until then, rest assured, I will use whatever format fits the circumstance (JSON, HTML, XML).

More on Ajax and returning data with or without markup

Brad Neuberg has a good post that discusses further the pros and cons of returning data to your Ajax requests, with out without markup.

What type of data should an Ajax call return?

This is a good post on The Ajax Response, discussing if it should be XML, HTML, or JSON. I personally think under no circumstances should it be HTML, or anything that includes markup. That violates the principle of separating the content from the style and it prevents reuse, by yourself and others.

I think deciding between JSON and XML is going to depend on your situation. XML is much more universal. With XML, you can create Web Services from your back end, and call them for display in PHP, JSP, and with Ajax. That Ajax call you are making today maybe a non-Ajax call you make later.

Google Suggest is a prime example of silliness. That data response is completely unusable in any other scenario. Perhaps, knowing Google, they have done this on purpose to prevent others from using that feed as freely, but it could be a handy service to offer and implement in other locations. The way Google has chosen to implement it, would require Google to have many versions of that response, for multiple uses.

With the rare exception, when you serve up data from your back end, think in big picture terms of making that data available to all your front end applications, and then apply style (HTML, CSS, etc) to it, once the data is in the front end.

UPDATE: Ignore my reservations about HTML in AJAX responses and see my followup post: AJAX Returning HTML (change of opinion).

« Previous PageNext Page »


Close
E-mail It