提交表单并保持在同一页面上? [英] Submit form and stay on same page?
本文介绍了提交表单并保持在同一页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< form action =receiver.plmethod =post >
< input name =signedtype =checkbox>
< input value =Savetype =submit>
< / form>
我想保留在同一页面上,点击提交时,仍然有 receiver.pl
执行。
应该怎么做?
解决方案
最简单的答案是:jQuery。这样做:
$(document).ready(function(){
var $ form = $( 'form');
$ form.submit(function(){
$ .post($(this).attr('action'),$(this).serialize(),function(response ){
//在这里做成功
,'json');
return false;
});
});
如果您想要动态添加内容并且仍然需要它,并且还需要多个表单,你可以这样做:
$('form')。live('submit',function(){
$ .post($(this).attr('action'),$(this).serialize(),function(response){
//在成功时做一些事情
},'json ');
返回false;
});
I have a form that looks like this
<form action="receiver.pl" method="post">
<input name="signed" type="checkbox">
<input value="Save" type="submit">
</form>
and I would like to stay on the same page, when Submit is clicked, but still have receiver.pl
executed.
How should that be done?
解决方案
The easiest answer: jQuery. Do something like this:
$(document).ready(function(){
var $form = $('form');
$form.submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){
// do something here on success
},'json');
return false;
});
});
If you want to add content dynamically and still need it to work, and also with more than one form, you can do this:
$('form').live('submit', function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){
// do something here on success
},'json');
return false;
});
这篇关于提交表单并保持在同一页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文