• Jquery来对form表单提交(mvc方案)


    来自:http://www.cnblogs.com/lmfeng/archive/2011/06/18/2084325.html

    我先说明一下,这是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"]就可以获取表单的值了。

  • 相关阅读:
    window 窗口对象http://www.diybl.com/course/1_web/javascript/jsjs/2007104/76401.html
    Web开发中的Drag&Drop完全手册http://www.cnblogs.com/birdshome/archive/2006/07/22/457369.aspx
    [转载]window 的 setTimeout() 與 clearTimeout() 方法
    javascript this详解(转) http://www.cnblogs.com/felix2007/archive/2007/03/21/682670.html
    关闭浏览器弹出对话框事件onbeforeunload http://www.blogjava.net/jennyli/articles/82351.html
    页面跳转http://www.9ba.cn/post/235.html
    POJ 3667 Hotel
    hdu 2511 汉诺塔 X
    UESTC Another LCIS
    Hdu 1576 A/B
  • 原文地址:https://www.cnblogs.com/liujiale/p/5325190.html
Copyright © 2020-2023  润新知