亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

呼啦一陣風 2019-10-26 13:12:35
我有一個看起來像這樣的表格<form action="receiver.pl" method="post">  <input name="signed" type="checkbox">  <input value="Save" type="submit"></form>并且我想停留在同一頁面上,單擊“提交”后,但仍然receiver.pl執行了。應該怎么做?
查看完整描述

3 回答

?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

最簡單的答案:jQuery。做這樣的事情:


$(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;

   });

});

如果您想動態添加內容并且仍然需要它來工作,并且還需要使用多種形式,則可以執行以下操作:


   $('form').live('submit', function(){

      $.post($(this).attr('action'), $(this).serialize(), function(response){

            // do something here on success

      },'json');

      return false;

   });


查看完整回答
反對 回復 2019-10-26
?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

使用XMLHttpRequest


var xhr = new XMLHttpRequest();

xhr.open("POST", '/server', true);


//Send the proper header information along with the request

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


xhr.onreadystatechange = function() { // Call a function when the state changes.

    if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {

        // Request finished. Do processing here.

    }

}

xhr.send("foo=bar&lorem=ipsum");

// xhr.send(new Int8Array()); 

// xhr.send(document);


查看完整回答
反對 回復 2019-10-26
  • 3 回答
  • 0 關注
  • 479 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號