This week's giveaway is in the Testing forum. We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line! See this thread for details.
Hi, I am having trouble with this callback function(belos), all I want to do is completely change a document with the results from the server (using document.open() etc), I have simplified this function just for the example, in my app it may be a fragment that needs injecting into the current page. This code works fine on Firefox but IE seems to have a problem when it reaches the document.open method. If anyone knows how to do this or a workaround I'd be very happy. Thanks all.
because I dont know until the response comes back from the server that I do need to replace the whole page. I may need to just update the page with some validation failures if that is what is returned from the servlet/jsp. However if a complete page is returned I am trying to display it.
Not the best way to do it. Have the server return either the validation information or the URL of the page to display, rather than the content of the page itself.
as I am using struts to return the page I'd have to somehow override that functionality to just return the URL, which i was hoping to avoid. thanks again for your help.
Struts or otherwise, you can return whatever you want.
If you are going to be working with Ajax, you need to move beyond the "always return a full HTML page" mentality.
For this type of situation, a JSON construct telling the on-page script what to do is a good approach, [ August 12, 2008: Message edited by: Bear Bibeault ]
Ok, I have been trying stuff based on your suggestion, Now my app works like this: 1. user submits form data. 2. struts validates, if unsuccessful the errors returned are displayed (by injection on page using ajax) 3. if validation passes then data is saved to the database - at this point the user needs to be redirected to a different page. The ajax callback function is still waiting for a server response, so the response it now gets is a JSON object name value pair {"theURL", "/webapp/action.do"} I then use document.location to display the required page.
Do you think this is the best way to do it or have i missed something?