zoukankan      html  css  js  c++  java
  • Form表单提交数据的几种方式

    一、submit提交

    在form标签中添加Action(提交的地址)和method(post),且有一个submit按钮(<input type=’submit’>)就可以进行数据的提交,每一个input标签都需要有一个name属性,才能进行提交。

    <form action=’http://www.123.com/postValue’ method=’post’>

    <input type=’text’ name=’username’ />

    <input type=’password’ name=’password’/>

    <input type=’submit’ value=’登陆'/>

    </form>

    当点击登陆时,向服务端发生的数据是:username=username&password=password.

    这种默认的提交方式,一般会进行页面的跳转(不成功时跳转到当前页面)。而有时候我们是对弹出框进行数据提交的,希望提交成功则关闭弹出框并刷选父页面,失败则提示失败原因,且弹出框不关闭。此时可以采用Ajax进行数据提交.

    二、Ajax提交form表单

    $('#documentForm').submitForm({
                url: "/Document/SubmitDocumentCreate",
                dataType: "text",
                callback: function (data) {
                    endFileUpload();
                    data = eval("(" + data + ")");
                    alert(data.Content);
                    if (data.Result > 0) {
                        location.href = data.Redirect;
                    }
                },
                before: function () {
                    startFileUpload();
                    var errMsg = "";
                }
            }).submit();

    此时可以在callback函数中对请求结果进行判断,然后执行不同的动作(页面跳转或刷选数据、提醒错误都可以)

    三、Easyui的form插件

    通过easyui的form插件也可以达到上面的目的。

    $('#ff').form('submit', {

    url:...,

    onSubmit: function(){

    //进行表单验证

    //如果返回false阻止提交

    },

    success:function(data){

    alert(data)

    }

    });

    四、form表单提交附件

    需要设定form的enctype="multipart/form-data"并且添加<input type=’file’>

    而且附件只能通过submit方法进行提交,

  • 相关阅读:
    标识符
    注释
    关键字
    第一个JAVA程序
    JAVA运行机制
    每个程序员都应该知道的延迟数
    构建WebDriverAgent时报错“xxx: no identity found Command CodeSign failed with a nonzero exit code”解决办法
    执行 sh ./Scripts/bootstrap.sh -d 时提示“xcrun: error: unable to find utility “simctl”, not a developer tool or in PATH ”错误解决办法
    stf ios版本部署
    centos 7安装一机多控stf客户端
  • 原文地址:https://www.cnblogs.com/Jxwz/p/4509618.html
Copyright © 2011-2022 走看看