views:

61

answers:

2

In an AJAX call back in drupal it is normally recommended to use drupal_json() to send data to client. This function converts the raw data into JSON along with HTML encoding.

I want to send the HTML data without encoding to client. for this I am using following code:

print $html_output;
exit(0);

Is there any recommended or best way in drupal to do so?

A: 

That will do the trick. Allthough you should invoke hook_exit first. However this is shortcutting the framework some what, it may work in simple cases but wont work for forms etc.

The only time I have used this method is if I am printing some data which is allready json encoded.

Jeremy French
+2  A: 

If you need to output only the HTML output returned from the menu callback, then the following code is the correct one:

print $html_output;
module_invoke_all('exit');
exit();

If you want your output to appear together the blocks Drupal normally output, then the code needs to be changed to the following:

return $html_output;
kiamlaluno