• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

AJAX does not send data

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   Greetings to all!

    Code in JSP:


 In Servlet




   But ajax does not  fulfil post method.



 
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem I see (besides the code formatting which is all over the place) is that you are not stopping the default action of the form submission. If you want to make an Ajax call rather than actually submitting the form, you either need to call the preventDefault method of the event, or return false from the event handler.

Why aren't you using jQuery to do all this? Makes it tons easier.
 
Andrey Dmitriev
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:One problem I see (besides the code formatting which is all over the place) is that you are not stopping the default action of the form submission. If you want to make an Ajax call rather than actually submitting the form, you either need to call the preventDefault method of the event, or return false from the event handler.




   To make is so, for example?




Why aren't you using jQuery to do all this? Makes it tons easier.



  Yes, i'll try it later
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So now, the page will not submit as you have blocked that. How does the behavior change? Use the network tab in DevTools to see if any request is being generated. Any errors in the console log?
 
Andrey Dmitriev
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   Noting is changed

   And there is no errors in log.

   
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the Networking Panel show that a request is generated?
 
Andrey Dmitriev
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   And developer console does not show any problems
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Does the Networking Panel show that a request is generated?

 
Andrey Dmitriev
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Bear Bibeault wrote:Does the Networking Panel show that a request is generated?




 Failed to load resource: the server responded with a status of 404 ()
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That likely means your URL is malformed. What happens when you try to load that URL directly into the browser?

Also, why is your URL absolute, versus server-relative? You could run into CORS issues.
 
Andrey Dmitriev
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:That likely means your URL is malformed. What happens when you try to load that URL directly into the browser?



  When I try to load that URL directly into the browser  In Safari this URL forwards me on correctly page.   But, doing this in Chrome, i get the empty page...


Bear Bibeault wrote:Also, why is your URL absolute, versus server-relative? You could run into CORS issues.



      I have used relative URL in AJAX, but withot success.  

But in html-form-submit it works properly: for example


    I'm confused....


 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!