title: How to parse json response and add functions like error,complete to it using JQuery?
body: <p>I am working on making a mini app using Json parsing . Output I am getting by hitting url   <a href="http://localhost:3000/cities.json" rel="nofollow">http://localhost:3000/cities.json</a> is as below</p>
  
  <pre><code>[
      {
      "id": 1,
      "name": "Bangalore"
      },
      {
      "id": 2,
      "name": "Chandigarh"
      },
      {
      "id": 3,
      "name": "Chennai"
      },
      {
      "id": 4,
      "name": "Hyderabad"
      },
  ]
  </code></pre>
  
  <p>I have parsed this using function     </p>
  
  <pre><code>  $.getJSON("http://localhost:3000/cities.json?&amp;callback=?", function(data) {
                  //something something
   }
  </code></pre>
  
  <p>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 </p>
  
  <pre><code>.error(function(){alert("error");})
  </code></pre>
  
  <p>I tried it in following way</p>
  
  <pre><code>  $.getJSON("http://localhost:3000/cities.json?&amp;callback=?", function(data) {
                  //something something
           }).error(function(){
              alert("error");
           })
  </code></pre>
  
  <p>I tried it using this way as well  </p>
  
  <pre><code>     var cities = $.getJSON("http://localhost:3000/cities.json");
                     cities.error("hi");        
  </code></pre>
  
  <p>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 ? </p>
  
  <p>------<strong>EDIT</strong>--------</p>
  
  <p>Also tried using </p>
  
  <pre><code> 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"); });
  </code></pre>
  
  <p>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 <strong>http://localhost:3000/cities.json</strong>
  always tend to give error irrespective of server running or not </p>