Ajax request gets to server but page doesn't update - Rails, jQuery

Posted by Jesse on Stack Overflow See other posts from Stack Overflow or by Jesse
Published on 2010-03-18T05:29:34Z Indexed on 2010/05/11 13:04 UTC
Read the original article Hit count: 221

Filed under: Error when finding categories...

So I have a scenario where my jQuery ajax request is hitting the server, but the page won't update. I'm stumped...

Here's the ajax request:

$.ajax({
    type: 'GET',
    url: '/jsrender',
    data: "id=" + $.fragment().nav.replace("_link", "")
});

Watching the rails logs, I get the following:

Processing ProductsController#jsrender (for 127.0.0.1 at 2010-03-17 23:07:35) [GET]
Parameters: {"action"=>"jsrender", "id"=>"products", "controller"=>"products"}
  ...
Rendering products/jsrender.rjs
Completed in 651ms (View: 608, DB: 17) | 200 OK [http://localhost/jsrender?id=products]

So, it seems apparent to me that the ajax request is getting to the server. The code in the jsrender method is being executed, but the code in the jsrender.rjs doesn't fire. Here's the method, jsrender:

def jsrender
    @currentview = "shared/#{params[:id]}"   
    respond_to do |format|
        format.js {render :template => 'products/jsrender.rjs'}
    end
end

For the sake of argument, the code in jsrender.rjs is:

page<<"alert('this works!');"

Why is this? I see in the params that there is no authenticity_token, but I have tried passing an authenticity_token as well with the same result.

Thanks in advance.

© Stack Overflow or respective owner