I still am confused regarding Ajax technology. And I still cannot answer this question of mine as I am still trying to grasp the technology.
Its regarding posting data with the server. In normal non-ajax web app, I usually do PRG (Post-Redirect-Get) pattern when I am doing a POST command. I have learned that this will prevent double submit problem or when the user tries to refresh the page or perform some Back-Forward transaction at the browser.
In Ajax, you do not perform a redirect because this will defeat the purpose of ajax as this is what the tutorials and books that I am folowing is saying
In Jquery, when I perform
$(document).ready(function(){
$("#myForm").submit(function(){
$.post("test.htm", function(data){
alert("Successfully save data");
}, "json");
//prevent page refresh
return false;
});
});
and the user performs, refresh(F5) or user performs a Back and Forward browser transaction.
Am I not risk of having double submit problem? Will the browser reload my click event again.
Sorry if this might sound too dumb to others but I just want to clarify my thoughts for a newbie like me.
It depends on where you put that code, if that code is on a click event handler for a button or something, then reloading the page will not re-trigger the click. If you just drop that code exactly as is on your page (or in a $(document).ready function) then, yes, reloading the page will re-submit that request.
Since ajax is triggered by a user action, double submitting isn’t a problem unless the user performs that action twice. Since you’re handling everything in javascript anyway, it is easy to remove that action – or the button the user is clicking – after they have done that action once.
Does that make sense? Hope that helps.