Parser error when using jQuery-UJS for remote link_to in Rails 3 app: how can I debug this?

后端 未结 7 1987
刺人心
刺人心 2021-02-14 12:55

I\'m trying to replace the content of a div after clicking on a link using Rails 3, remote_link :remote => true and jQuery.

So far, I\'ve been able to ge

7条回答
  •  -上瘾入骨i
    2021-02-14 13:36

    I was also getting odd parsererrors even though my remote links were correctly pointing to actions with :format => :js and my controller actions were correctly using respond_to to serve up JSON objects like:

    respond_to do |format|
      format.js do
        render :json => {:something => "OK"}
      end
    end
    

    The solution ended up being just dropping this line into my application.js:

    $.ajaxSettings.dataType = "json";
    

    By default, it appeared that jQuery was trying to evaluate all responses as "script", which I guess means it was trying to execute it as code—? Dropping this line in once fixed the issue globally.

提交回复
热议问题