簡體   English   中英

在提交之前使用 javascript/jQuery 從表單中提取 post 參數

[英]extracting the post parameters from a form using javascript/jQuery before submission

在使用 javascript(最好是 jQuery)提交之前,如何獲取使用 method=post 提交的任何表單的參數。 我想要做的是獲取帖子參數並將其提交到備用位置。 我正在使用

$('form').submit(function() {
  alert('action=  ' + $(this).attr("action"));
  alert('serialized string' + $(this).serialize());
  return false;
});

但它僅適用於獲取請求,我也想從發布請求中提取參數。

像這樣的東西對我有用

$('#form').submit(function(){
        $.post(your_location, $(this).serialize());
    return false;
  });

如果您不想使用 $.post(),您可以使用任何其他您喜歡的 Ajax 方法。 您還可以包含一個回調方法來處理您的 ajax 調用返回的任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM