我有以下形式:Rails的远程投掷形式的SyntaxError
<%= form_for [@commentable, Comment.new], :remote => true do |f| %>
<%= f.text_area :body %>
<%= f.submit "Add your comment" %>
<% end %>
然后控制器(严重剥夺了基本的部分):
def create
respond_with(@comment) do |format|
format.html { redirect_to params[:return_url] }
format.json { render :layout => !request.xhr? }
end
end
然后这里是处理的JavaScript表单AJAX:
$('#new_comment')
.bind('ajax:success', function(evt, data, status, xhr){
var $this = $(this);
// Append response HTML (i.e. the comment partial or helper)
$('#comments ol').append(xhr.responseText);
$('#comments ol li:last-child').effect("highlight", {}, 3000);
// Clear out the form so it can be used again
$this.find('input:text,textarea').val('');
// Clear out the errors from previous attempts
$this.find('.errors').empty();
})
.bind('ajax:error', function(evt, xhr, status, error){
// Display the errors (i.e. an error partial or helper)
$(this).find('.errors').html(xhr.responseText);
});
表单提交正常,评论被附加,因为它应该,但Safari的Web检查或者在提交评论表单时显示我在任何页面的第1行(这只是文档类型)的SyntaxError: Parse error
,我找不到原因。
甚至不知道从哪里开始。
不行。仍然得到相同的错误。 – Shpigford 2011-05-25 19:58:48