ElkArte Community

General => Chit Chat => Topic started by: IchBin on June 02, 2013, 01:26:25 am

Title: Ajax question
Post by: IchBin on June 02, 2013, 01:26:25 am
Am I understanding this right when it comes to doing an ajax call. If I only want to return certain data (not the whole shebang with header and footer crap), can't I just do this?

ob_clean();
add_my_shizzle();
obExit();

Does it not work that way? Trying to do some ajax stuff with some old code in SMF and am not able to figure this out.
Title: Re: Ajax question
Post by: emanuele on June 02, 2013, 05:21:10 am
If I remember correctly you may simply do:
Code: [Select]
loadTemplate('YourXmlTemplateFile');
$context['template_layers'] = array();
$context['sub_template'] = 'your_xml_template';
Title: Re: Ajax question
Post by: Arantor on June 02, 2013, 10:25:57 am
It sort of depends. Doing what Ema suggests will - at least assuming you haven't changed SMF too much - return  a block of Content-Type: text/html, with no XML content type and no XML header. Trying to use it as XML may be... interesting. Certainly the core functions expect real XML which must be sent much as IchBin suggests (though you usually need to add a header() call to set Content-Type after the ob_clean call)

Look at how SMF/Elk does it, action=quotefast should be a good example.
Title: Re: Ajax question
Post by: IchBin on June 02, 2013, 10:00:49 pm
Thanks for the tips guys. I actually just applied this to the TinyPortal shoutbox as well. I hacked that ajax a while ago in a dirty way, and didn't like it much. Ema's little tip worked much better than what I was doing. I'll check out the xml way down the road when/if I rewrite stuff.