返回的 RJS 代码不执行
我正在使用 jQuery 和 Rails。我正在尝试发出 PUT 请求来更新任务。呼叫成功。但是,返回的 javascript 代码不会执行。代码正常返回,但只是不执行。
这是我正在发出的 jQuery put 请求。
$("#droppable_<%= bin.id -%>").droppable({
drop: function(event, ui) {
div_ids = ui.draggable.attr('id').split('_');
$.post('/tasks/' + div_ids[div_ids.length - 1], {'task[bin_id]' : '<%= bin.id -%>', _method:'PUT'}, function(data) {
});
}
});
这是 rjs 代码。
render :update do |page|
page.alert 'success'
page.remove "draggable_#{params[:id]}" if old_bin_id.to_s != params[:task][:bin_id]
page.replace_html "count_#{old_bin_id}", current_user.tasks.bin(old_bin_id).size
page.replace_html "count_#{params[:task][:bin_id]}", current_user.tasks.bin(params[:task][:bin_id]).size
end
这是我完成请求后得到的结果。
try {alert("success");jQuery("#draggable_2").remove();jQuery("#count_2").html("");jQuery("#count_3").html("2");} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"success\");\njQuery(\"#draggable_2\").remove();\njQuery(\"#count_2\").html(\"\");\njQuery(\"#count_3\").html(\"2\");'); throw e }
这是正确的,但它只是不执行。知道为什么吗?
I am using jQuery with rails. I am trying to make a PUT request to update a task. The call is made successfully. However, the javascript code returned does not execute. The code is returned alright but it just does not execute.
Here is the jQuery put request i am making.
$("#droppable_<%= bin.id -%>").droppable({
drop: function(event, ui) {
div_ids = ui.draggable.attr('id').split('_');
$.post('/tasks/' + div_ids[div_ids.length - 1], {'task[bin_id]' : '<%= bin.id -%>', _method:'PUT'}, function(data) {
});
}
});
This is the rjs code.
render :update do |page|
page.alert 'success'
page.remove "draggable_#{params[:id]}" if old_bin_id.to_s != params[:task][:bin_id]
page.replace_html "count_#{old_bin_id}", current_user.tasks.bin(old_bin_id).size
page.replace_html "count_#{params[:task][:bin_id]}", current_user.tasks.bin(params[:task][:bin_id]).size
end
This is what I get on completion of the request.
try {alert("success");jQuery("#draggable_2").remove();jQuery("#count_2").html("");jQuery("#count_3").html("2");} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"success\");\njQuery(\"#draggable_2\").remove();\njQuery(\"#count_2\").html(\"\");\njQuery(\"#count_3\").html(\"2\");'); throw e }
Which is correct but it just does not execute. Any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为如果你想使用 jQuery 处理 rjs 有两种方法可以做到这一点:
或者
Because if you want to handle rjs using jQuery there are two way to do that:
or