在Mootools上发布请求

时间:2014-09-06 09:24:52

标签: ajax post mootools

我是MooTools的新手,并尝试将带有表单内容的Ajax请求发送到网址。

<form method="post" enctype="multipart/form-data" action="<?= $PHP_SELF; ?>" name="fn" id="fn">
<input name="user_name" id="user_name">
<input name="user_mail" id="user_name">
<input name="user_text" id="user_name">
<input type="file" name="attach">
<input id="button" type="button" value="Submit">
</form>

<script type="text/javascript">
    $('button').addEvent('click', function(event) {
        var req = new Request({
            method: 'post',
            url: 'url.php',
            onSuccess: function(response) {
                alert(response);
            });
    });
</script>

当我点击按钮时,没有任何反应。如何正确地从表单传输数据?

1 个答案:

答案 0 :(得分:0)

您的代码看起来不错,您遗失了}但除此之外您只是忘了添加.send();

req.send();类似,您实际上可以将数据作为参数传递给该方法。

测试并检查here about the .send() method

建议您的代码如何:

<script type="text/javascript">
    var req = new Request({
        method: 'post',
        url: 'url.php',
        onSuccess: function(response) {
            alert(response);
        } // < --- You actually missed this one
    });

    $('button').addEvent('click', function(event) {
        req.send();
    });
</script>
相关问题