1

How can I do a HTTPget response code on a bogus link on javascript?

I really have no idea what HTTP response codes are and for.

Kyemme
  • 27
  • 1
  • 5

2 Answers2

0

From Use javascript to check http status codes

$(function() {
  var url = "some_url";
  $.ajax(url,
  {
     statusCode: {
     404: function() {
        alert('page not found');
     }
  }).done(function( msg ) {
     alert( "Data Saved: " + msg );
  });
});  

See http://en.wikipedia.org/wiki/List_of_HTTP_status_codes For detailed info on what these mean

Community
  • 1
  • 1
ioseph
  • 1,887
  • 20
  • 25
  • Just realised you mean a get request, updating answer now – ioseph May 27 '14 at 03:54
  • No, don't edit your answer. It is what I'm looking for. Just a follow up questions. How do I test if that function? and how I locate (header/body) and call (onclick/.ready) that function? – Kyemme May 27 '14 at 03:59
  • replace 'url' with the address of your server. Inside the `404: function() { ` you can fire any handlers you want. For more info on getting the status code / body see http://api.jquery.com/jquery.ajax/ – ioseph May 27 '14 at 04:07
0

You can try this way also

$( document ).ready(function() {
  var url = "/customers/customer_list";
  $.ajax({url:url,
    data: { name: "John", location: "Boston" }
    type: "GET",
    dataType: "html"
    success:function(result){
      alert(result);
    }});
}});    
Abhroo
  • 126
  • 8