With rails code:
使用rails代码:
= button_to "-", availability_time_span_path(ts) ,:method => :delete, :remote => true
I generate html form, which should be posted via ajax:
我生成html表单,应该通过ajax发布:
<form action="/availability_time_spans/175" class="button_to" data-remote="true" method="post">
<div>
<input name="_method" type="hidden" value="delete">
<input type="submit" value="-">
<input name="authenticity_token" type="hidden" value="n962qRxizeXeoEwWYv2AlMfT4nKxxp9ITUxm5wp1nZo=">
</div>
</form>
When I click on the submit button it is posted twice. Once as: text/javascript from jquery.js:8417 , second time as: text/html from Other
当我点击提交按钮时,它会被发布两次。一次为:来自jquery.js的文本/ javascript:8417,第二次为:来自其他的text / html
2 个解决方案
#1
1
SOLVED
Problem was I previously inject code using ajax, but renderer response with layout, so the whole jquery was initialized for the second time.
问题是我之前使用ajax注入代码,但渲染器的布局响应,所以整个jquery第二次初始化。
respond_with @ra
If I render response to ajax call with no layout, then it is fine.
如果我在没有布局的情况下呈现对ajax调用的响应,那么就可以了。
respond_with @ra, :layout => false
#2
0
This could happen for a couple of reasons
这可能由于几个原因而发生
- You might have the Javascript cached in your browser. Try clearing your cache or opening the page up in a different browser.
- 您可能在浏览器中缓存了Javascript。尝试清除缓存或在其他浏览器中打开页面。
- You might be serving up precompiled assets. Make sure you have
config.serve_static_assets = false
in your config file. - 您可能正在提供预编译资产。确保配置文件中有config.serve_static_assets = false。
#1
1
SOLVED
Problem was I previously inject code using ajax, but renderer response with layout, so the whole jquery was initialized for the second time.
问题是我之前使用ajax注入代码,但渲染器的布局响应,所以整个jquery第二次初始化。
respond_with @ra
If I render response to ajax call with no layout, then it is fine.
如果我在没有布局的情况下呈现对ajax调用的响应,那么就可以了。
respond_with @ra, :layout => false
#2
0
This could happen for a couple of reasons
这可能由于几个原因而发生
- You might have the Javascript cached in your browser. Try clearing your cache or opening the page up in a different browser.
- 您可能在浏览器中缓存了Javascript。尝试清除缓存或在其他浏览器中打开页面。
- You might be serving up precompiled assets. Make sure you have
config.serve_static_assets = false
in your config file. - 您可能正在提供预编译资产。确保配置文件中有config.serve_static_assets = false。