Welcome Guest, Not a member yet? Register   Sign In
AJAX search results filtering
#1

[eluser]RS71[/eluser]
Hello

I'm thinking of building a filter for my search results but instead of having users reload the page, I wanted it update automatically via AJAX(jQuery).

What would be the best approach for this?

At the moment, I believe that whenever a user alters a filter, I'd have have jQuery send it's parameter to a page to store it in a session (not send all filters, just that one). After its stored in a session, I'd have it call a results page that fetches all filters stored in the session, generate results and update the page.

What do you guys think? Would it be too strenuous to the server to have it update the session on every filter change? It would be best to use non DB sessions yes?

Thanks in advance guys.
#2

[eluser]Mike L[/eluser]
I wouldn't use sessions at all.

Since your using jQuery, you can stick this in your constants file.

Code:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

Now you can do this.

Code:
if(IS_AJAX)
{
    // code that responds to ajax calls goes here
}
else
{
    // code that runs when there is no ajax call (normal page load, javascript is disabled etc...).
}
#3

[eluser]RS71[/eluser]
What method do you suggest?
#4

[eluser]bretticus[/eluser]
I don't see any need to store the parameters in a session when you have all the variables "in state" right there on the page. If you do go with sessions, it's just a little extra data passed back form the server. Not huge overhead. Database sessions are more overhead because your server has to make an extra connection to a database (though unless you have torrents of hits, you probably won't notice significant performance issues.)
#5

[eluser]bretticus[/eluser]
[quote author="Mike L" date="1253490427"]
Code:
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
...

Code:
if(IS_AJAX)
{
    // code that responds to ajax calls goes here
}
else
{
    // code that runs when there is no ajax call (normal page load, javascript is disabled etc...).
}
[/quote]

That's a great little addition. I did this the other day and handled it in the controller method. 8-/
#6

[eluser]BrandonDurham[/eluser]
FANTASTIC tip. Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB