2009-06-18 42 views
0

我试图用一个表格通过邮寄发送原型Ajax请求的PHP脚本,然后显示如何使用PHP的Ajax.Request的onsubmit

我目前使用此代码对成功和失败的警告窗口

<div id="reservationRequestForm"> 
    <form name="requestReservationForm" method="post" onsubmit="new Ajax.Request('admin/process/process_reservation_request.php', {onSuccess: function() {alert('Success');} , onFailure: function() {alert('Failure');}, method:'post'}; return false;"> 

.... 

    <input type="submit" class="buttonGreen" value="Send Request" onClick="hideDiv('reservationRequestForm');"/> 
    </form> 
</div> 

我不希望响应被处理(无论如何都是空的)。我只想知道它是成功还是失败。

另外。当js被禁用时,我希望表单能够优雅地退化。

现在这段代码什么都不做。我究竟做错了什么?

+0

使用原型而不是jQuery :) – 2009-06-18 23:59:21

+0

你能发布更多的html吗?目前发生了什么?是提交的形式(不应该)? – 2009-06-19 00:02:14

回答

1

如果onsubmit事件没有被处理,那么表单没有被提交。

你在表单中是否有下列其中一项?

<input type='submit' ... /> 

<input type='image' ... /> 

上面的两个元素点击(或用space/enter激活)将提交表单。你有onsubmit事件处理程序应该抓住它,并返回false应该停止默认操作(改变页面)。

而且,你的Ajax.Request调用实际上并不似乎使用任何形式的信息从形式本身。 Ajax.Request需要知道要发送的信息。

编辑 您正在琢磨一个闭合的括号。使用以下内容

<form name="requestReservationForm" method="post" onsubmit="new Ajax.Request('admin/process/process_reservation_request.php', {onSuccess: function() {alert('Success');} , onFailure: function() {alert('Failure');}, method:'post', parameters:Form.serialize(this) }); return false;">