I am working on making a mini app using Json parsing . Output I am getting by hitting url http://localhost:3000/cities.json is as below
[
{
"id": 1,
"name": "Bangalore"
},
{
"id": 2,
"name": "Chandigarh"
},
{
"id": 3,
"name": "Chennai"
},
{
"id": 4,
"name": "Hyderabad"
},
]
I have parsed this using function
$.getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
//something something
}
Now I want to add .error function to it so in case there is some issue with response or say server doesnt respond i may get to know about it say by putting an alert like
.error(function(){alert("error");})
I tried it in following way
$.getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
//something something
}).error(function(){
alert("error");
})
I tried it using this way as well
var cities = $.getJSON("http://localhost:3000/cities.json");
cities.error("hi");
But none of them is working. To check for error i stop my local server and it doesnt give me any alert for that . Please guide me which way should i proceed ?
------EDIT--------
Also tried using
var jqxhr = $.getJSON("http://localhost:3000/cities.json?callback=?", function() {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
in case my localhost:3000 server is running it give me alert success and second success but in case i stop it no error call, also making url just http://localhost:3000/cities.json always tend to give error irrespective of server running or not