1

I am working on a Padrino app running on my local server(localhost:3000). I am exposing a get call /location which is returning a json response. I am hitting this API from the javascript code written separately. Here is what i am writing:

$.get("http://localhost:3000/location", function(data) {    
    alert("Inside callback" + data); 
});

(PS : using jquery 1.9.1, tried getJSON also) The http end point is getting hit and returning sucess code 200 with json response but the success call back handler is not being called in the javascript. Why is that happening? Any way to do so?

  • If you want to get JSON use `$.getJSON` instead of `$.get`. (http://api.jquery.com/jQuery.getJSON/) – Kasyx Mar 12 '13 at 11:26

2 Answers2

0

You are missing an ) at the end, like:

$.get("http://localhost:3000/location", function(data) {    
alert("Inside callback" + data); 
});

For JSON you might want to consider using getJSON instead, and catch the error if something went wrong.

You can also use the low-level ajax call and check if there was an error:

$.ajax({
    url: 'http://localhost:3000/location',
    type: 'GET',
    success: function(data){ 
        alert('success');
    },
    error: function(request,error) {
        alert(request.responseText); 
    }
});
L-Four
  • 13,345
  • 9
  • 65
  • 109
0

Try it like:

$(document).ready(function(){
    $.get("http://localhost:3000/location", function(data) {    
        alert("Inside callback" + data); 
    });// here you are missed closed parenthesis ')'
});
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106