Answers

Question and Answer:

  Home  AJAX

⟩ How do I handle the back and forward buttons in AJAX?

While you could go out and create a custom solution that tracks the current state on your application I recommend you leave this to the experts. Dojo addresses the navigation in a browser neutral way as can be seen in the JavaScript example below.

function updateOnServer(oldId, oldValue,

itemId, itemValue) {

var bindArgs = {

url: "faces/ajax-dlabel-update",

method: "post",

content: {"component-id": itemId, "component-value":

itemValue},

mimetype: "text/xml",

load: function(type, data) {

processUpdateResponse(data);

},

backButton: function() {

alert("old itemid was " + oldId);

},

forwardButton: function(){

alert("forward we must go!");

}

};

dojo.io.bind(bindArgs);

}

The example above will update a value on the server using dojo.io.bind() with a function as a property that is responsible for dealing with the browser back button event. As a developer you are capable of restoring the value to the oldValue or taking any other action that you see fit.

 176 views

More Questions for you: