After an Ajax call I reload a web page. I have two options..
-
I can send the page as responseText and have it write to the screen using document.write().
-
I can send a control to Javascript telling it to reload the web page using window.location.href.
Option 1 is good because it takes only one round trip instead of two. However the onload Event was not triggered as it would with a normal reload.
Option 2 is good because it triggers the onload Event.
Is there any way to to get the best of both worlds…i.e. I would like to send the page using responseText but also have it loaded like a new page, once it is recevied.
I simply does not make sense to make 1.5 trips instead of .5 trips when you are on the server (control is on the server) and need to reload the page. Is this a weakness of Ajax or do I just not know hot to do it?
Related:
*
Ok from what I see you want to load a new page when an user registers. The best way to do this is without ajax. As the page gets loaded and the onLoad event gets fired.
But you also want to check if the email the user used is already in use. The way I like to do this is to make a variable and set it to false. The use the onchange event of the email input field to run an ajax validation. And if the email is available and valid I set the variable to true. And I add a function to the button’s onsubmit event and return the variable. This way the user gets redirected only if the email is available.
Or:
You can move all of your code from the onLoad event into a function. And simply call it when you get set the page using response text. And rather than using ‘document.write()’ I’d recommend using
document.body.innerHTMLanddocument.head.innerHTML.