• ajax表单提交


    HTML代码:

    <form id="formCity" action="/SiteMap/Search" method="get" onsubmit="return false">
        <div class="form-group">
            <div style="padding: 0; line-height: 30px; float: left; font-size: 16px; ">
                快速查找:
            </div>
            <div class="col-md-3">
                <input id="city_search" name="search" class="form-control" data-provide="typeahead" type="text" value="" required />
            </div>
        </div>
        <input class="btn btn_main_sm" value="搜索" type="submit" onclick="findCity('formCity')">
    </form>

    Js代码:

    <script type="text/javascript" src="/Resource/Scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/Resource/Scripts/jquery.validate.Extend.js"></script>
    <script type="text/javascript">
        function findCity(formId) {
            var form = $("#" + formId);
            var valid = form.valid();
            var method = form.attr("method");
            var action = form.attr("action");
            var btnSubmit = form.find("[type=submit]");
            var btnText = btnSubmit.val();
            if (valid) {
                $.ajax({
                    type: method,
                    url: action,
                    beforeSend: function () {
                        btnSubmit.addClass('disabled').text("正在查询...");
                    },
                    data: form.serialize(),
                    success: function (data) {
                        if (data.IsSuccess) {
                            location.href = data.Message;
                        }
                        else {
                            alert(data.Message);
                        }
                        btnSubmit.removeClass("disabled").text(btnText);
                    }
                   , error: function (XMLHttpRequest, textStatus, errorThrown) {
                       alert("NetworkError:" + XMLHttpRequest.status + " " + XMLHttpRequest.statusText)
                       btnSubmit.removeClass("disabled").text(btnText);
                   }
                })
            }
    
        }
  • 相关阅读:
    深入分析String类型(一)
    创建泛型类
    XML数据的读取—数据库配置文件
    Config配置文件读写
    jQuery动画
    设置屏幕快捷键
    jQuery事件
    jQuery操作DOM
    Python 二进制文件网址
    Centos使用crontab自动定时备份mysql的脚本
  • 原文地址:https://www.cnblogs.com/genesis/p/5775486.html
Copyright © 2020-2023  润新知