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?

4

2 回答 2

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); 
    }
});
于 2013-03-12T11:26:12.993 回答
0

试试看:

$(document).ready(function(){
    $.get("http://localhost:3000/location", function(data) {    
        alert("Inside callback" + data); 
    });// here you are missed closed parenthesis ')'
});
于 2013-03-12T11:28:04.697 回答