I am working on creating a gadget using Json parsing. The output I get is by clicking the url http: // localhost: 3000 / cities.json below
[ { "id": 1, "name": "Bangalore" }, { "id": 2, "name": "Chandigarh" }, { "id": 3, "name": "Chennai" }, { "id": 4, "name": "Hyderabad" }, ]
I analyzed this with a function
$.getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
Now I want to add the .error function to it, so if there is any problem with the answer or say the server is not responding, I can find out by adding a warning, for example
.error(function(){alert("error");})
I tried it as follows
$.getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
I also tried using this method
var cities = $.getJSON("http://localhost:3000/cities.json"); cities.error("hi");
But none of them work. To check for an error, I stop my local server and it does not give me any warnings about it. Please tell me which direction should I continue?
------ 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 working, it gives me a warning and a second success, but in case I donโt stop it, throw an error by also making the URL only http: // localhost: 3000 / cities.json always give an error regardless of server operation or not