This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

document.open in ajax callback function

 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Sincerly

Stu.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stu Johns:
in my app it may be a fragment that needs injecting into the current page
Well which is it? Injecting a fragment is substantially different from replacing the whole document.
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The bit giving me trouble is where I am trying to replace the whole document, in an ajax callback function.

thanks

Stu
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to replace the entire page, than why in the world are you using Ajax? A simple post back will do it.

Eric
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks for helping.

Stu
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just to add, its IE6 this fails in.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Stu.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thanks

Stu.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds pretty much like how I would do it.
 
Stu Johns
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent! Thanks for the advice
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic