1

My server "return HttpResponse()" when succuess, "return HttpResponse(status=400)" when failed. My client has following jquery ajax function:

$('#submit').click(function(){
   $.post("{% url 'addcomment' %}", {msg:$('#newcomment').val()}, function(data,status){
       if (status==200) {
          location.reload()
       } else {
          alert("Comment failed")
       }
   });
});

But the ajax code doesn't work. Any idea?

Henrik Andersson
  • 45,354
  • 16
  • 98
  • 92
Leon
  • 75
  • 5
  • possible duplicate of [How to get response status code from jQuery.ajax?](http://stackoverflow.com/questions/5344145/how-to-get-response-status-code-from-jquery-ajax) – Hedde van der Heide Apr 25 '13 at 08:47

1 Answers1

0

As the documentation clearly states, the success callback returns a data, textStatus and jqXHR argument

http://api.jquery.com/jQuery.post/#jQuery-post-url-data-successdata--textStatus--jqXHR-dataType

If you want the response status get it from the third argument jqXHR.status

Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100