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

Ajax Submitting page and referesing but not suppose to be

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I m trying to create a "Yes" or "No" db update using ajax, but noticed page is refreshing not getting expected output.
In action class db got sucessfully updated but div tag not updating the sucess response also page is getting refreshed. I tried putting alerts and sysout, sucess response from action class, but when I append the response in div it's not showing and page is refreshed.

Please let us know how to debug this..

Please find the code below.

1. JSP Page : StatusChange.jsp. Action class successfully invoked and db got updated. And writing the output in results.jsp



results.jsp






 
Sheriff
Posts: 67636
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
Why are you doing Ajax "by hand" rather than using jQuery (or something similar)?
 
Bear Bibeault
Sheriff
Posts: 67636
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
P.S. You should be returning false from your submit handler to stop the default action of the form submission.
 
Kumanan Guna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:P.S. You should be returning false from your submit handler to stop the default action of the form submission.



Could you please explain more on this? do I need to add any additional parameter in JSP page to make that return as false ?
 
Bear Bibeault
Sheriff
Posts: 67636
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

may catlog wrote:

Bear Bibeault wrote:P.S. You should be returning false from your submit handler to stop the default action of the form submission.



Could you please explain more on this? do I need to add any additional parameter in JSP page to make that return as false ?



It has nothing to do with JSP. You need to add return false; to the end of your submit handler. Otherwise, the form will go ahead and submit as usual; which I take it you do not wish to do as you are making an Ajax call in lieu.

And again, writing Ajax calls yourself is error-prone and fragile. You should be using jQuery or another Ajax library.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic