ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to determine, if a template is loaded via ajax or not?

August 30, 2011 2:34pm

Subscribe [3]
  • #1 / Aug 30, 2011 2:34pm

    thomasaull

    14 posts

    Is it possible to determine in a template if it’s loaded via an ajax-request or not? The reason is to deliver different templates for each kind of request.

  • #2 / Aug 31, 2011 3:07am

    John Henry Donovan

    12339 posts

    Hi thomasaull,

    Can you give some more context and an example of what you are trying to achieve here please.
    What types of requests other than ajax are you referring to?

  • #3 / Aug 31, 2011 5:08am

    thomasaull

    14 posts

    I’m trying to implement a live search function for my Blog on http://www.thomas-aull.de/blog
    The tricky part is, that the template path to my search results is fixed in my exp:search:simple_form Tag. I can’t change it later in my ajax request, it simply doesn’t work.

    However, i need different output for a search request via ajax and a normal search (if someone has javascript disabled for example).

    So, the idea was, to determine inside the template if the request is via ajax.

    Do you get my problem?

  • #4 / Sep 01, 2011 11:50am

    Mark Bowen

    12637 posts

    Hi thomasaull,

    There is no built-in method in ExpressionEngine to determine if a page was loaded by Ajax however I do know of a plugin MX Ajax Detect which is reported as working on ExpressionEngine 2.x

    Does that help at all?

    Mark

  • #5 / Sep 01, 2011 11:52am

    thomasaull

    14 posts

    I’ll try this out asap!

  • #6 / Sep 01, 2011 12:15pm

    thomasaull

    14 posts

    Ok i tried the MX Ajax Detect Plugin. Basically it works fine, but unfortunately when i try to use it for my live-search it don’t. I think it’s because there is a redirect or anything and so the HTTP-Header “HTTP_X_REQUESTED_WITH” = XMLHttpRequest” gets lost…

    Any chances for another solution?

  • #7 / Sep 01, 2011 1:00pm

    Mark Bowen

    12637 posts

    I think this post is moving more into a how-to now as there isn’t anything built-in to ExpressionEngine that will allow for this to be done I’m afraid.

    You could contact Max about that plugin as he is a very approachable / knowledgeable chap and so might be able to help out further with the problems you’re having.

    Other than that I think that this post would be best suited to the Community Help forums to see if anyone else has ever done this sort of thing.

    Would you like me to move the post there for you?

    Thanks.

    Mark

  • #8 / Sep 01, 2011 1:10pm

    thomasaull

    14 posts

    Yes please move it for me, thanks!

  • #9 / Sep 01, 2011 2:11pm

    Mark Bowen

    12637 posts

    Yes please move it for me, thanks!

    Et voila! 😉

    Hopefully someone will be able to help out here on this one although I’d still recommend contacting Max as he’s really good at those sorts of things.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases