0

I am making a ajax post call that returns the required information in the response header an the empty response body . I am using the following code to make call

$.ajax({
  url : someUrl,
  type : "post",
  contentType : "application/x-www-form-urlencoded",    
  success : function(data, textStatus, request)
  {
        alert("success");
  },
  error : function(request, textStatus, errorThrown)
  {
        alert("error");     
  },
  timeout : "150000"
}); 

i always get error alert since the response is empty even though the status is 200 ok. Is there any workaround for the calls like this?

Gowsikan
  • 5,571
  • 8
  • 33
  • 43

1 Answers1

0

For example, we want to get Date header from the URL which returns error:

var get = $.get('http://stackoverflow.com/asdasdasddsadsadasde').always(function(){
    alert(get.getResponseHeader('Date'));
});

success and error methods are deprecated in latest versions of jQuery. You may use done, fail and always methods.

Andrey Ozornin
  • 1,129
  • 1
  • 9
  • 24