• 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

AJAX : How can I set response type other than 200 ("OK") in Server Response

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

From my servlet I'm setting i.e other than 200 ("OK") message ! But while checking at client side using AJAX like



The alert stating "ERROR", is not executing ? Whats the problem ?
 
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
Because of the wonky formatting of your posted code (is that really how you write your code?) I can't tell what's going on. it looks like your alert is outside any conditional that checks the error code, so it should display always. If not, then you're not getting to that block of code at all.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the formatting !

Here is AJAX 'call back handler' code



else block at line 1 , is not executing , Im expecting it because , In my Server side Servlet action , I wrote


So where I'm wrong ?
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to set the response status to something else other than 200 incase of an error.


That should work in your case.
PS: your code formatting is still awfully wonky. Bugs resulting from lack of proper indentation can give you awful nightmares in the future.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anirvan Majumdar:
You need to set the response status to something else other than 200 incase of an error.


Ok, Thanks for the help ! I ll try !

Originally posted by Anirvan Majumdar:


PS: your code formatting is still awfully wonky.



Can you please let me know whats the wonky thing about my above code ?

I put only a part of code , which is of interest !
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you insist, let me try highlighting the issue with your indentation.
This is how your code appears to be:
----------------------------------------

A much better way of writing the code above would be:
-----------------------------


Now you might argue that there's not much to it, in which case, I guess there's nothing much to say. Putting in a little bit of effort to structure your code not only helps you minimise errors, but also helps those who try and go through the code to help you fix an error.
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... 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