views:

104

answers:

2

Hi again...

I have a form that onsubmit calls an ajaxFunction()... The ajaxfunction calls a php function which returns results from a mysql db...

Problem is the back button... I want users to be able to search and then search again and then use the back button to get back to the previous search, but this wont work... Remember, the form doesnt really submit, it calls an ajaxfunction...

Do I have to make the form submit in order to use the back button?

BTW I have tried submitting the form, but the page just gets refreshed and the ajaxfunction doesnt get called and that leads to no mysql results because the php file never got called!!!

Thanks for all help guys... and let me know if you need more input...

A: 

You can submit the form to a named anchor on the current page which won't cause a server request.

Your form:

<form action="#anchor">
...
</form>

Your form's destination (on the same page)

<a name="anchor">...</a>

If you do this, the back button will navigate back to your pre-form submit address in the address bar without a page reload.

UPDATE: Try using Really Simple History :)

Asaph
yes, but if i ignore the server request, then the back button wont work on my site...
Camran
@camran: Check out "Really Simple History". I updated my answer with a link.
Asaph
sorry dont understand what you mean... This is what I want: hit enter key, ajax gets variables from drop lists and sends to php script, php checks variables against db, result is displayed in a div on the site...
Camran
@camran: Got it. Ok, and then after the user does the things you mentioned above, you then would like the user to be able to hit the back button in their browser and return to the pre-search state without reloading the page?
Asaph
exactly what i want
Camran
@camran: Ok, so the Really Simple History link might help you with the part that I mentioned.
Asaph
@camran: from the RSH link: "RSH serializes application data in an internal JavaScript cache so that bookmarks and the back button can be used to return your application to an earlier state."
Asaph
Asaph, do you know any Jquery?www.blocket.se how the hell does this site work,,, please help me find out?Thanks man u r really helpful
Camran
@camran: Sorry, I'm not a JQuery guy (yet). But you can certainly accomplish what you're trying to do without JQuery. And if you have a JQuery specific question, there are lots of experts on StackOverflow to answer JQuery questions.
Asaph
A: 

I think that having the users hit the "back" button pretty much defeats the benefit of an ajax-enabled form.

Right before you call your ajax function, clear the innerHTML attribute of the div so that you start with a clean slate. Or to allow the users to control it, provide the functionality in a button.

document.getElementById("divid").innerHTML = "";

or jQuery:

$("#divid").html("");

EDIT/UPDATE: I cannot hit the site for some reason, but they are probably using some jQuery or Javascript to catch the unload event of the page. SO uses something like this. You could use that event to call the stuff I mentioned above:

$(window).unload(function() { 
    $("#divid").html(""); 
});
Buggabill
check out this site www.blocket.seThey have this function, and they use Jquery which I dont understand too much...How have they managed to make this possible?By the way, could you figure out what database system they are using while at it?
Camran
Not sure if determining their database type is possible....
Buggabill