zoukankan      html  css  js  c++  java
  • Jquery来对form表单提交(mvc方案)

    我先说明一下,这是asp.net mvc 里面的用法,

    Jquery来对form表单提交,下面是一个form表单,里面没有action字段,我们来用Jquery注册事件进行提交,

    <form method="post" id="documentForm">
        <input type="hidden" id="hidId" name="hidId" value="<%=Request.QueryString["id"] %>" />
        <input type="hidden" id="hidAction" name="hidAction" value="<%=Request.QueryString["action"] %>" />
        <div class="fieldbody">        
            <div class="tagsiglebody">
                <table class="create">
                    <tr>
                        <th class="w100">
                            关键字:
                        </th>
                        <td class="nes">
                            <input type="text" id="txtKeyword" name="txtKeyword" class="txt w250" value="<%= ViewData.Eval("keywords") %>"
                                isnull="0" />
                            关键字请用逗号隔开
                        </td>
                    </tr>               
                </table>
            </div>
        </div>
        <div class="btngroup">
            <input type="button" class="btncreateok" id="btnConfirm" value="创建" />
            <input type="button" class="btncreatecancel" onclick="history.go(-1)" value="取消" />
        </div>
        </form>

    在js中的代码如下:

    $(document).ready(function () {
        $("#btnConfirm").click(function () {
            $('#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();
        });

    }

    在js中,我们一定要注意,$(document).ready是必须的,不然会出错,其中对button、form的id进行事件绑定:$("#btnConfirm").click、$('#documentForm').submitForm

    然后在$('#documentForm').submitForm方法中给出url和回调方法。

    好了,这下就完成了,当然那怎么在Document/SubmitDocumentCreate中获取表单的值呢,用Request.Form["xxxxx"]就可以获取表单的值了。

  • 相关阅读:
    javascript的组成
    BOM
    相等操作符
    arguments
    数组
    Tomcat日志时间的时区问题
    利用脚本批量操作Solr集群(SolrCloud)
    Solr的schema.xml(managedschema)文件
    Solr报警告The _default configset could not be uploaded
    Ubuntu创建用户
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2084325.html
Copyright © 2011-2022 走看看