Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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 ?
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic