I have two rails applications. In the first application i have the following method in my controller:
def delivery_status
envelope_id = params[:id]
render :json => envelope.to_json(:include => [:deliveries, :log_lines])
end
which, if go to the url in my browser, nicely shows my the JSON. Seems ok. However, if i call this through jQuery, from my second application, using the following:
$(document).ready(function(){
$('#provisioning_sms_details_dialog').hide();
$('.get_sms_details').live('click', function(event) {
var el = $(this),
data_url = el.attr('data-url');
$.ajax({
url: data_url,
dataType: 'text',
success: function(data, status, req) {
alert('received with status' + status)
alert('received json ' + data);
}
});
});
});
then the right url is hit with the correct parameters but data
is always empty.
I first tried using $.getJSON
, then$.get
to end at $.ajax
. I am not sure but it seems i am doing something wrong at server-side.
If i look at the request inside firebug, the response is indeed empty. Yet, i do not understand, if let the browser hit the same url, i get my json object.
Any insights how to solve this?