• 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 bind a Javascript function / AJAX call to display an alert

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have an EditUser.jsp which has a form, with multiple users, the id for each is submitted to a DeleteServlet via the form action "deleteUser". A request forward after the delete redirects the user back the list of users, the functionality all works.

However, there can be a case where the logged in user can attempt to delete themselves, Ive blocked this on the back end, but I would like to render a popup on the front end to say this.

I managed to hook up a AJAX call, but this would not open the popup, and would display the message on the page transition I mentioned above, from the form action.

Some snippets below:
main.js


DeleteUserServlet.java


showUsers.jsp (just a snippet of the form)


The for I hoped for was, hit delete -> check the user -> if loggedin user -> show popup -> user dismisses popup

ARE THERE ANY BETTER SOLUTIONS! I know nothing about JS, or JQuery, this small project is to try and learn so...
Any help appreciated.

My source for trying to implement this is from: webpage

The strange thing is, when I use the chrome dev tools and type the function name in the console, it works, just when running the app, it wont open the
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand that correctly (and I think I do, it's a pretty clear set of example code) then the client doesn't know the current user ID. It's kept in the session on the server, but I don't see it being sent to the client. If that's the case then it wouldn't be possible for the Javascript code to check whether the user is trying to delete themselves.

But what you've got seems like a reasonable start. You just need to fix the servlet to forward to the showUsers JSP in all cases, and if the user tried to delete themselves then set a request attribute which will cause that JSP to include a message saying so.
 
reply
    Bookmark Topic Watch Topic
  • New Topic