Skip to main content
Topic: Ajax question (Read 5939 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Ajax question

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.
Last Edit: June 02, 2013, 02:44:51 am by IchBin
Success is not the result of spontaneous combustion, you must set yourself on fire!

Re: Ajax question

Reply #1

If I remember correctly you may simply do:
Code: [Select]
loadTemplate('YourXmlTemplateFile');
$context['template_layers'] = array();
$context['sub_template'] = 'your_xml_template';
Bugs creator.
Features destroyer.
Template killer.

Re: Ajax question

Reply #2

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.

Re: Ajax question

Reply #3

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.
Success is not the result of spontaneous combustion, you must set yourself on fire!