直接上代码,我就不多写了。。。
以下是HTML代码:【复制
<form method="post" name="form1" action="test.php">
<input type="text" id="a" name="a" size="" maxlength="" value="Ajax测试" /> <input type="button" value="Ajax Test" onclick="AjaxTest(this.form);" />
</form>
以下是Javascript代码:【复制
<script type="text/javascript" src="prototype.js">
</script>
<script type="text/javascript">
< !--
function AjaxTest(theForm) {
//alert(theForm.action);
new Ajax.Request(theForm.action, {
method: 'post',
parameters: Form.serialize($(theForm)),
onComplete: function(transport) {
alert(transport.responseText);
}
});
}
//-->

</script>
以下是PHP代码:【复制
<?
//test.php
echo $_POST['a'];
?>
GET方式很简介。。。自己看手册。。。还是写一下吧,免得自己也忘了
以下是Javascript代码:【复制
new Ajax.Request('test.php', {
method: 'get',
onSuccess: function(transport) {
alert(transport.responseText);
},
onFailure: function() {
alert('出错啦。。。')
}
});
prototype.js功能很强大,偶只看了点皮毛。。。要好好看看手册