您需要提出一个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页面,并包含您的形式,并包含一些代码,以指示的形式发出AJAX请求,B组分当用户单击“提交”按钮,然后在结果div中显示由B组件返回的内容。
而且这可能是你B.mc组件:
has 'mytext';
%class>
I got this text from your form,
and its length is .
结果会是这样: