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.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

document.open in ajax callback function

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to add, its IE6 this fails in.
 
Bear Bibeault
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds pretty much like how I would do it.
 
Stu Johns
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent! Thanks for the advice
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic