我想说,在这种情况下,您根本不需要使用form标记。
<div id="add_value_form"> <!-- input fields --> <input type="button" value="Add" onclick='post_form("/add_value");' /></div>编辑 正如保罗所说Bergantino我还要避免使用内嵌的Javascript。因此,请改用:
<div id="add_value_form"> <!-- input fields --> <input type="button" value="Add" /></div>
Java脚本
$(document).ready(function() { $('.formSubmitButton').click(function() { $.post('/add_value', {'test':'test'}, function(data) { $("#add_value_form").empty().append($(data)); }, "text"); });});更新
由于这仍然会引起问题,因此我将对该
$.ajax方法进行一些测试。另外,我不认为POST调用会被缓存,但以防万一,请尝试将缓存设置为false。确保您没有序列化问题的另一项测试是将已编码的数据传递给您。如果您仍然遇到问题,可以尝试将dataType设置为text
$.ajax({ url: '/add_value', type: 'POST', cache: false, data: 'test=testValue', dataType: 'text', complete: function(xhr, textStatus) { alert('completed'); }, success: function(data) { alert(data); }, error: function(xhr, textStatus, errorThrown) { alert('woops'); }});


