当我尝试打通过JavaScript这个动作,我得到一个错误406 Not Acceptable
:怪异“406不能接受的”错误
def show
@annotation = Annotation.find_by_id(params[:id])
respond_to do |format|
format.html {
if @annotation.blank?
redirect_to root_path
else
redirect_to inline_annotation_path(@annotation)
end
}
format.js {
if params[:format] == "raw"
render :text => @annotation.body.to_s
else
render :text => @annotation.body.to_html
end
}
end
end
这是jQuery的,但我做了正确的beforeSend东西:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "text/javascript");
},
cache: false
});
这里是我的请求头:
Host localhost:3000
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Accept text/javascript
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Content-Type application/x-www-form-urlencoded
请将您的答案标记为正确的答案......从来没有想过我会添加关于该评论的评论,但它使查找答案变得容易得多。 – erroric 2013-06-10 17:08:10
看看这里:http://stackoverflow.com/questions/25910031/jquery-autocomplete-throws-406-not-acceptable-error – 2014-12-29 13:32:51