javascript
html 抓取 post 请求,javascript – 获取HTML Form Post方法的返回值
您需要發出AJAX請求.雖然不是絕對必要,但我建議你使用
jQuery,它會讓事情變得容易多了.另請看這個問題:
jQuery AJAX submit form
這是Mason的一個小例子,它當然非常簡化,你應該添加一些錯誤檢查和一些轉義,但我認為這可能是一個好的開始.您的A.mc組件可能如下所示:
This is A$(document).ready(function() {
$("#myform").submit(function() { // intercepts the submit event
$.ajax({ // make an AJAX request
type: "POST",
url: "B", // it's the URL of your component B
data: $("#myform").serialize(), // serializes the form's elements
success: function(data)
{
// show the data you got from B in result div
$("#result").html(data);
}
});
e.preventDefault(); // avoid to execute the actual submit of the form
});
});
它只是一個加載jQuery庫并包含表單的HTML頁面,它包含一些代碼,用于指示表單在用戶單擊Submit按鈕時向B組件發出AJAX請求,然后顯示B組件返回的內容你的結果div.
這可能是你的B.mc組件:
has 'mytext';
%class>
I got this text from your form,
and its length is .
結果將是這樣的:
總結
以上是生活随笔為你收集整理的html 抓取 post 请求,javascript – 获取HTML Form Post方法的返回值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android中注册的账号密码储存在,A
- 下一篇: gradle idea java ssm