0

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?

1 Answer 1

1

Is this a cross domain request? In that case your ajax-request would be of type HEAD, and you would only see an empty body. Ajax calls are restricted by the same origin policy.

If that is the case, you could look into using JSONP, which would solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.