提交表单并停留在同一页面上? [英] Submit form and stay on same page?

查看:32
本文介绍了提交表单并停留在同一页面上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的表单

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>

我想在点击提交时停留在同一页面上,但仍然执行了 receiver.pl.

and I would like to stay on the same page, when Submit is clicked, but still have receiver.pl executed.

应该怎么做?

推荐答案

最简单的答案:jQuery.做这样的事情:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆