我有一个post表单,我希望submit以AJAX方式完成,但我不想更改页面 URL。
例如:
<form action="/countries/change_country" data-ajax="true" method="post">
<select name="country_code">
<option value="FR" selected="selected">France</option>
<option value="DE">Germany</option>
</select>
<input type="submit" value="change country" />
</form>
当我单击change country按钮时,表单是通过 AJAX 发送的,但页面 URL 更改为/countries/change_country不好的,因为我的服务器中不存在此 URL,这对 HTTP 动词非常挑剔。
我知道可以为整个应用程序更改此默认行为,但我想停用changePage()此表单的唯一行为。