[英]Mootools catch form data on submit on the same page
这个人伤了我的脑筋。
我试图从表单中获取$ _POST数据,并在mootools框架中使用Ajax将其放在与表单相同页面的div中。 而且我无法使其正常工作,成功消息显示,div仅填充:Array()。
php文件很简单:
<?php
print "<pre>".print_r($_POST, true)."</pre>";
?>
这是我的JavaScript:
window.addEvent('domready', function() {
$('form-booking').addEvent('submit', function(event) {
event.stop();
var log = $('log_res').empty().addClass('ajax-loading');
this.set('send',{
url: this.get("action"),
data: this,
update: log,
onComplete: function(response) { log.removeClass('ajax-loading');
alert('Succesvol aangevraagd.'); $('log').setStyle('background','#ffffff');
}
}).send();
});
});
更新
Header:
Connection Keep-Alive
Content-Length 0
Content-Type text/html
Date Fri, 09 Mar 2012 12:06:17 GMT
Keep-Alive timeout=5, max=100
Location http://192.168.52.64/xampp/
Server Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By PHP/5.3.1
开机自检:
<pre>Array
(
[date_from] => 1331300252
[service_check_8] => 1
[service_check_34] => 1
[booking_form] => 1
[cnt_nights] => 7
[cnt_person] => 2
[cnt_children] => 0
[cnt_baby] => 0
[child_ages] => Array
(
[0] => 2
[1] => 2
[2] => 2
[3] => 2
[4] => 2
[5] => 2
[6] => 2
[7] => 2
[8] => 2
[9] => 2
[10] => 2
[11] => 2
[12] => 2
[13] => 2
[14] => 2
[15] => 2
[16] => 2
[17] => 2
[18] => 2
[19] => 2
)
[service_cnt_8] => 2
[subservice_16] => 614
[service_cnt_34] => 1
[subservice_40] => 301
[subservice_88] => 688
[service_cnt_67] => 1
[subservice_122] => 762
[service_cnt_68] => 1
[subservice_123] => 765
)
</pre>
请下次,在格式化代码方面做得更好-这很难阅读...您可以尝试一下吗?
$('form-booking').addEvent('submit', function(e) {
new Event(e).stop();
var log = $('log_res').empty().addClass('ajax-loading');
this.send({
update: log,
onComplete: function() {
log.removeClass('ajax-loading');
}
});
});
“ Array()”来自php-您需要更改代码中的某些内容:
首先,添加一个method: post
到您设置发送的位置。 PHP正在打印$ _POST数组,该数组为空,因此您将确切地看到所看到的响应。 这不是mootools问题。
另外,您的$('log')。setStyle ...将不起作用,因为您的日志div似乎具有id'log_res'(除非您有2个不同的日志元素正在进行中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.