• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to refresh using javascript without the alert

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When popup is closed I need to reload the contents of main page.
I have acheived this using
window.parent.location.relaod();
But it shows an alert before reload. Only on the click of retry the page refreshes.

I tried window.parent.location.reload(true) and (false)... Nothing seems to be posted. The updated values dont appear on main page .

Does anyone know how to do this?
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You say alert... would confirm box be more suitable. With confirm(), you can check for the ok or cancel buttons and act accordingly. Eg ok button trigger reload.

Also which window are you reloading or referring to? Current window/page or parent window (meaning current window in opened through say window.open())?
 
Udhayha Dhayalan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:You say alert... would confirm box be more suitable. With confirm(), you can check for the ok or cancel buttons and act accordingly. Eg ok button trigger reload.

Also which window are you reloading or referring to? Current window/page or parent window (meaning current window in opened through say window.open())?



I think you got my question wrong. I am opening a popup from parent window. On close of the poup I need to refresh my parent window.
I have done this using window.opener.location.reload()
The parent window refreshes like I expect.
But I use IE8.On reload it throws an alert by default, saying Information needs to be resent. If you want to continue press Retry or press Cancel to avoid duplicate transaction.

It does reload after I press retry. But this looks like an error message. So is there some way to refresh the page without this message being thrown?
 
Sheriff
Posts: 67746
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
That's because you are using HTTP improperly and leave a dangling POST.

Please read this article on proper structure of web applications, and play particular attention to the PRG Pattern.
 
Udhayha Dhayalan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:That's because you are using HTTP improperly and leave a dangling POST.

Please read this article on proper structure of web applications, and play particular attention to the PRG Pattern.



Thank you for the response.
I have read through the article.
Can you tell me what I need to do. I have called the poup window using GET method like this
window.open('/DashBoard/showAdminPopup.do?arg='+ address.join(','),'editPopup','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=500');

For the parent window and the rest of the project I have used normal Struts action which would be POST I suppose. How can I handle the POST properly so that its not dangling anywhere?
 
Bear Bibeault
Sheriff
Posts: 67746
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
Use the PRG pattern. After the POST is completed, redirect to the page controller which creates a GET and will not try to re-run the POST upon refresh.

If you have your task controllers and page controllers mixed up, then your design needs attention. Read the article again. Task controllers should react to submissions; page controllers should prepare pages for display. Too many people put both task and page control in the same action. They should be separate.
 
Udhayha Dhayalan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Use the PRG pattern. After the POST is completed, redirect to the page controller which creates a GET and will not try to re-run the POST upon refresh.

If you have your task controllers and page controllers mixed up, then your design needs attention. Read the article again. Task controllers should react to submissions; page controllers should prepare pages for display. Too many people put both task and page control in the same action. They should be separate.



Im sorry if this sounds silly. Im new to this concept. I want the main page to be open. I want a popup window to show and close. On the close of poup I need to refresh the main page to get updated content.
and Im using GET method only for popup.
In this case do I have to end the POST method before calling the popup?? Will my main page still be alive?
 
Bear Bibeault
Sheriff
Posts: 67746
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
This all really has nothing to do with the popup. It's the main page that's causing the problem. You 'll likely run into the same issue if you hit refresh on the main page.

The point of the PRG pattern is to eliminate having the POST repeated upon refresh. So the processing should be as follows:

1) POST is submitted to the server.
2) The task controller responds to the post and performs the necessary actions.
3) The task controller redirects to the page controller for the page to be displayed. This results in a GET to the page controller.
4) The page controller does what it needs to do to prepare the page for display and forwards to the JSP.

This means that when a refresh occurs, the GET for the page controller is executed, rather than the task controller for the POST.

This of course cannot work if the task and page controllers are conflated as is the case in 99.9999999999% of web apps written.

Most people write their controllers as a mix of task and page controllers. Does your action perform the processing and then forward to the page? If so, it does not adhere to PRG.
 
Udhayha Dhayalan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok you are right. PRG pattern seems to be the right solution.
And it has nothing to do with popup. The same alert shows up even when I simply refresh the page

But I still dont understand how to implement it
I dont find any example in any site...
 
Bear Bibeault
Sheriff
Posts: 67746
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
I gave you the steps in my previous reply, and it's outlined in the article. They keys to the whole concept are:

  • Make sure that each page has a page controller that operates independently of any tasks. The only purpose of this controller is to prepare a page for view (fetch its data to be displayed from the DB, perform computations, and so on).
  • Make sure each task controller only peforms the task that is subimittted to it (usually with a POST), and doesn't try to prepare the next page for processing. That's the job of the page controller.
  • When the task controller is done its job, it redirects (not forwards) to the page controller for the page to be displayed.


  • This means that a refresh will only cause the page controller to run so that the page can be re-displayed. The task performed by the task controller never gets executed by a refresh.
     
    We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic