提交表格并停留在同一页面上?

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


<form action="receiver.pl" method="post">

  <input name="signed" type="checkbox">

  <input value="Save" type="submit">

</form>

并且我想停留在同一页面上,单击“提交”后,但仍然receiver.pl执行了。


应该怎么做?


呼啦一阵风
浏览 443回答 3
3回答

慕姐4208626

最简单的答案:jQuery。做这样的事情:$(document).ready(function(){&nbsp; &nbsp;var $form = $('form');&nbsp; &nbsp;$form.submit(function(){&nbsp; &nbsp; &nbsp; $.post($(this).attr('action'), $(this).serialize(), function(response){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // do something here on success&nbsp; &nbsp; &nbsp; },'json');&nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp;});});如果您想动态添加内容并且仍然需要它来工作,并且还需要使用多种形式,则可以执行以下操作:&nbsp; &nbsp;$('form').live('submit', function(){&nbsp; &nbsp; &nbsp; $.post($(this).attr('action'), $(this).serialize(), function(response){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // do something here on success&nbsp; &nbsp; &nbsp; },'json');&nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp;});

翻过高山走不出你

使用XMLHttpRequestvar xhr = new XMLHttpRequest();xhr.open("POST", '/server', true);//Send the proper header information along with the requestxhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xhr.onreadystatechange = function() { // Call a function when the state changes.&nbsp; &nbsp; if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {&nbsp; &nbsp; &nbsp; &nbsp; // Request finished. Do processing here.&nbsp; &nbsp; }}xhr.send("foo=bar&lorem=ipsum");// xhr.send(new Int8Array());&nbsp;// xhr.send(document);
打开App,查看更多内容
随时随地看视频慕课网APP