html 抓取 post 请求,javascript – 获取HTML Form Post方法的返回值

您需要发出AJAX请求.虽然不是绝对必要,但我建议你使用jQuery,它会让事情变得容易多了.另请看这个问题:jQuery AJAX submit form这是

您需要发出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 .

结果将是这样的: