Jquery 插入 表单提交后丢失
Jquery Insertions Lost after form submit
我有一个简单的对话框小部件,我用它来将一些值发送到服务器,并将一些东西添加到页面上显示的无序列表中。例如,名称 = 矩阵 A a11=1 a12=2 a21=4 a22=1因此,此数据将传递到服务器,并且 name 属性将附加到列表中。
用户按提交后,将调用 Validate() 例程,该例程验证条目,将名称条目附加到无序列表并提交表单。
但是,提交表单后,页面将重新加载,追加将丢失。有什么办法可以避免这种情况吗?我知道附加在我实际上可以看到它的一瞬间起作用,但随后页面重新加载,我们又回到了起点。
@EDIT:这是我代码的一部分。整个代码变得太大了,所以请查看此内容 -
<script>
$('#form1').submit(function(event){
event.preventDefault();
//Validate is a function which returns a bool if validation proceeds correctly
var isCorrect = Validate(this);
if(isCorrect){
//if validated correctly then submit, close widget, add name of matrix to a list
this.submit();
$('#dialog').dialog('close'); //the form sits inside a dialog widget
$('#selectable').append("<li class='ui-widget-content'>name</li>");
}
});
</script>
<form name='form1' id='form1' method='get'>
<fieldset>
<label for="Name">Name</label>
<input type='text' name='nameofmatrix' id='Name' class='whitepanes'><br>
<label for="a11">a11</label>
<input type="text" name='a11' id='a11' class='whitepanes number-field'><br>
<label for="a22">a22</label>
<input type="text" name='a22' id='a22' class='whitepanes number-field'><br>
<label for="a12">a12</label>
<input type="text" name='a12' id='a12' class='whitepanes number-field'><br>
<label for="a21">a21</label>
<input type="text" name='a21' id='a21' class='whitepanes number-field'><br>
<input type='submit' name='mysubmit' id='submit_button' value='submit'>
<button id='cancel_button'>cancel</button>
</fieldset>
</form>
您可能需要共享您的代码。
但是我要做的是在您的提交按钮上放置一个点击侦听器。 然后使用阻止默认值阻止页面重新加载。
例如
$('#buttonID').click(function(event){
event.preventDefault(); //important
// calculations here
// validate method
});
或者如mplungjan
所述,您可以在form
上使用submit
事件。
$('#formID').submit(function(event){
event.preventDefault(); //important
// calculations here
// validate method
});
相关文章:
- HTML表单提交时未执行外部函数
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 将图像上传ajax与表单提交ajax相结合
- Javascript无法处理表单提交
- 如何在我的情况下禁用表单提交
- 加载后的页面与ajax表单提交不起作用
- angularjs-控制器在表单提交时未调用
- 禁用带有字符白名单的表单提交
- 如何使用Google Analytics跟踪表单提交
- 使用javascript将表单提交到iframe目标中
- e.preventDefault在表单提交时被忽略
- AngularJS JQuery Ajax表单提交等效
- JavaScript表单提交帮助
- PHP表单提交和重定向
- 当所有输入文本字段都为空时,禁止表单提交,但当jquery中的任何字段不为空时允许提交
- setTimeOut AFTER jQuery表单提交
- Jquery 插入 表单提交后丢失
- 如何通过表单提交在插入后显示成功消息
- 流星-表单提交时没有插入到集合中
- 在表单中插入javascript按钮,但不在提交时发送表单