How does a page know if it is being called by ajax?



My web site HTML comes from a database via querystring e.g. page.asp?pid=55
I have a separate asp search page, search.asp. Its output is retrieved by an
ajax call from page.asp and its HTML is then neatly wrapped and styled by
I want search.asp to recognise if it is not being called via ajax from
page.asp, but directly e.g. via the address bar (and if so, redirect to
page.asp). Do I need to put something into the posted string, or (better) is
there an asp method that can do this?
The ajax call is
function GetSearchPage(st) {
var poststr = "searchterm=" + encodeURI(st);
makePOSTRequest('/search/search.asp', poststr,'divFullSearchDisplay');
Thanks, Giles



Old Pedant

You *can* look at HTTP_REFERER, but it's not really all that reliable (proxy
servers, firewalls, etc., can all distort or hide it).

And, in any case, if somebody simply types in the URL and/or hits it from
their FAVORITES, you won't have any REFERER.

The safer way, in my opinion, is to do the *OPPOSITE*. Assume that a full
page is needed and only deliver the Ajax version if a special magical key is
passed to you in the querystring.


Make up your own funky key. Even encrypt it if you don't want people
stealing your Ajax bandwidth.

NOW... If you *WANT* your Ajax "feed" to be public, then probably the best
choice is to not even try to do both things on one page. Just have two
different URLs. Heck, the one that produces full HTML page could even
#include the code for the other page.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question