Advertisement:

Author Topic: AJAX-related inquiry  (Read 765 times)

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,370
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
AJAX-related inquiry
« on: August 09, 2018, 10:47:40 AM »
Is it possible to dynamically load a function within a template file without loading the header and footer?

Assuming that the URL loads:

website.com/index.php?action=xyz

I've managed to work it by using exit(); at the very end, but in case there's a better method, I'd like to know.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,637
    • StoryBB/StoryBB on GitHub
Re: AJAX-related inquiry
« Reply #1 on: August 09, 2018, 11:26:24 AM »
Set $context['template_layers'] to an empty array to skip them.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,370
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: AJAX-related inquiry
« Reply #2 on: August 09, 2018, 08:14:16 PM »
On a similar note, how do I stop Google from crawling these AJAX-based pages?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,637
    • StoryBB/StoryBB on GitHub
Re: AJAX-related inquiry
« Reply #3 on: August 10, 2018, 02:59:00 AM »
Don’t link to them in the first place?

Failing that there is a directive you can set in $context to emit a no index, but I don’t remember what it is offhand.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,370
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: AJAX-related inquiry
« Reply #4 on: August 10, 2018, 10:42:53 AM »
Don’t link to them in the first place?

Failing that there is a directive you can set in $context to emit a no index, but I don’t remember what it is offhand.

It's hard not to, and even if I don't via some javascript code, search engines still get to them

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,370
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: AJAX-related inquiry
« Reply #5 on: August 16, 2018, 11:09:33 AM »
One more question based on my original inquery, I tried this:

Code: [Select]
function search()
{
global $context;

$context['template_layers'] = array();

echo'My Text';
}

It comes up as a white screen with "my text" then underneath: An Error Has Occurred! Unable to load the 'main' template.

What does that suggest?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,637
    • StoryBB/StoryBB on GitHub
Re: AJAX-related inquiry
« Reply #6 on: August 16, 2018, 11:55:24 AM »
That suggests you haven’t set up $context['sub_template'] to point to the template_ function that should be handling your output because separating out the logic of processing from its output is great.

If you need to spit out JSON and no other stuff, echo the json_encode then call obExit(false) to send without any other processing.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Study Force

  • SMF Hero
  • ******
  • Posts: 3,370
    • StudyForcePS on Facebook
    • @studyforceps on Twitter
    • Study Force
Re: AJAX-related inquiry
« Reply #7 on: August 16, 2018, 12:09:15 PM »
Thank you