weixin_33736649 2014-09-06 09:24 采纳率: 0%
浏览 19

在Mootools上发布请求

I'm new to MooTools and trying to send Ajax request with form content to the url.

<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>

When I click on button, nothing happens. How right transferring data from form?

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2014-09-06 10:12
    关注

    Your code looks good, you had a } missing but aside from that you just forgot to add a .send();

    Like req.send();, and you can actually pass the data as a argument to that method.

    Test that and check here about the .send() method.

    Suggention to how your code could look like:

    <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>
    
    评论

    报告相同问题?

    悬赏问题

    • ¥15 存储过程或函数中的结果集类型变量如何使用。
    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信