HTML5表单提交 [英] HTML5 Form Submit

查看:103
本文介绍了HTML5表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一种形式的行动向一个IP地址,而无需打开IP地址。

I am trying to get a form to submit an action to an ip address without open the ip address.

所以,当我点击提交按钮,我希望它发送post命令到IP(在这种情况下,192.168.0.1),只是刷新当前页面。

So, when I hit the submit button I want it to send the post command to the ip (in this case 192.168.0.1) and just refresh the current page.

<div data-role="main" class="ui-content">
<form method="POST" action="http://192.168.0.1/">
<input type="submit" name="parser" value="thisguy"/>
</form>
</div>

我是上运行的脚本提交:

My script that runs on submit:

<script src="http://ajax.googleapis.com/ajax/liubs/jquery/1.9.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
    $('form.ajax').on('submit', function() {
        var that = $(this),
            url = that.attr('action'),
            method = that.attr('method'),
            data - {};

        that.find('[name]').each(function() {
            var that = $(this),
                name = that.attr('name'),
                value = that.val();
            data[name] = value;

            $.ajax({
                url: url,
                type: method:,
                data: data,
                success: function(response) {}

            });

        });

        return false;
    });
</script>

现在它提交后,并尝试打开192.168.0.1作为网页。有人可以帮我借提供code时解释或指向我的命令?

Right now it submits the post and tries to open 192.168.0.1 as a webpage. Can someone help me out either by providing code with an explanation or pointing me to the command?

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

您需要prevent的默认操作(使用的 即preventDefault()

You need to prevent the default action (using e.preventDefault())

$('form.ajax').on('submit', function(e) {
    e.preventDefault(); // Prevent default submit action (that is, redirecting)
    var that = $(this),
        url = that.attr('action'),
        method = that.attr('method'),
        data = {};

    that.find('[name]').each(function() {
        var that = $(this),
            name = that.attr('name'),
            value = that.val();
        data[name] = value;

        $.ajax({
            url: url,
            type: method:,
            data: data,
            success: function(response) {}

        });

    });

    return false;
});

这篇关于HTML5表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆