jQuery AJAX request (Rails 3) gets redirected and returns empty message body!
Posted
by elsurudo
on Stack Overflow
See other posts from Stack Overflow
or by elsurudo
Published on 2010-06-15T04:44:10Z
Indexed on
2010/06/16
2:52 UTC
Read the original article
Hit count: 297
I'm trying to do a manual jQuery AJAX request the following way:
$("#user_plan_id").change(function() {
$("#plan_container").load('/plans/' + this.value);
});
I have the "rails.js" file included in my header, and a "<%= csrf_meta_tag %>".
I see from my log that the request IS getting to the server (although without the authenticity token... does rails.js even do this?), but the response is a 302 (Found) rather than 200, and no data actually gets rendered.
Any ideas?
Edit: I now see that the first request redirects, and the proper partial gets rendered on the redirect. However, the 2nd response's body (on the client-side) is still empty. I'm guessing jQuery uses the first response and doesn't have a listener set up for the redirect. How do I get around this?
Also, another note: the page doing the requesting is an HTTPS page.
Here is what my log says:
Started GET "/plans/221168073" for 127.0.0.1 at Tue Jun 15 01:24:06 -0400 2010
Processing by PlansController#show as HTML
Parameters: {"id"=>"221168073"}
DEPRECATION WARNING: Using #request_uri is deprecated. Use fullpath instead. (called from ensure_proper_protocol at /Users/ernestsurudo/Sites/vidfolia/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb:57)
Redirected to http://vidfolia.com/plans/221168073
Completed 302 Found in 1ms
Perhaps it has something to do with the deprecation warning?
© Stack Overflow or respective owner