解決方案:html
使用modal show事件代替在ajax獲取頁面加入js的方式ajax
下面是代碼json
js方面ui
$('#contactAddModal').on('loaded.bs.modal', function () { $("#contactAddForm").validate({ ignore: "", submitHandler: function(form){ $.ajax({ type: "POST", url: "/contacts/save2.do?orgId="+id, data: $("#contactAddForm").serializeArray(), dataType: 'json', success: function(result){ if (result.status == 1) { swal("提示", "新增成功", "success"); reflushPage(); } else { if (result.info == "") { toastr.success("數據異常!"); } else { toastr.error(result.info); } } } }); } }); }); $('#contactAddModal').on('hidden.bs.modal', function () { $(this).removeData("bs.modal"); $("#contactAddForm").empty(); $("#contactAddForm").html("數據正在加載..."); });
當前html頁面代碼this
<#-- 新增聯繫人--> <div class="modal fade" id="contactAddModal" role="dialog" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> </div> </div> </div>
ajax頁面url
<div class="modal-header"> <h4 class="modal-title">新增聯繫人</h4> </div> <div class="modal-body"> <div class="row"> <form id="contactAddForm" class="form-horizontal "> <div class="form-group"><label class="col-sm-3 control-label" for="chineseFullName"><span class="required-star">*</span>客戶中文全稱</label> <div class="col-sm-7"><input name="chineseFullName" type="text" class="form-control required"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-white" data-dismiss="modal">關閉</button> <button class="btn btn-primary" type="submit" >新增</button> </div> </form> </div> </div>