Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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 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
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

ajax POST call doesn't return with Success or Error

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, I have an EAR project built with Spring MVC 3.1.
I use jquery .ajax to submit a POST when uploading a photo.
When the photo is uploaded successfully for the first time, I deleted it via ajax call, then adding another photo with the ajax POST call for uploading another photo. But this time when I click the upload button, the ajax POST doesn't return with Success or Error.

Here is my jsp code for the javascript/ajax part:



After deleted the photo, the second time when I click on the Add New Pictures, the openUploadImagePage javascript function gets called, but there is no call back into its Success or Error function.

Controller:

@RequestMapping(value="/open_upload_image_page", method=RequestMethod.POST)
public @ResponseBody ProductBean open_upload_image_page(HttpServletRequest req, Model model) throws IllegalAccessException, InvocationTargetException
{
....
return productBean;

}



Any suggestion is very much appreciated.

Thanks
Sam
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First let's clean up the code. You're using jQuery, obviously, so why are you doing everything the hard way?

Rather than gathering up all the form elements "by hand", why aren't you just using jQuery's .serialize() method? In fact, you could be using the Forms plugin to make this even easier.

Then, get rid of the onclick attribute on the button, and establish the event hander using the .on() method; preferably establishing a submit handler on the form rather than a click handler for the button.
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the code cleaned up, open the debugging console in your browser (I like Chrome's dev tools a lot) and see what's actually going on. Is the second request even being made? If so, what's the response?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pop up blocker is going to block that window.open call since no user action triggered it to open.
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
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!