Return only the relevant data to AJAX requests?

I was thinking on how to AJAX-enable a web app, and I wanted to ask for an advice with this:

I want to add AJAX to certain pages, mostly it will be dynamic loading of data and updating parts as a response to user actions.
Lets say I want to update a part of the page. Should I just send a regular HTTPXML request and get the actual part out of the returned page on the client side, or add some sort of PHP Ajax controller to process AJAX requests on the server and return only the data that is actually needed?

What do you think?

Either way is potentially feasible. However, if you have HTML generation code written in PHP, writing javascript to do the exact same will cause maintainability issues.

There was an interesting topic here: which covered some of the pros/cons of each method.

As a rule of thumb I’d say:

-If you’re generating the HTML in php already, return HTML from the ajax request

-If the data is going to be processed by the client and not just used for constructing HTML then JSON (or potentially XML) is preferable.

If you’re using jQuery, you can use .load() to get only the element you want from the requested html. Something like:
$(‘#user_info’).load(‘user_info.php #user_info’);

I agree.