使用来自 MVC 页面的 jqModal ajax 调用的结果更新 div
这是我的场景。
我使用 jqModal 的 ajax 功能来调用 jqModal,该功能在模式对话框中显示表单。用户填写一些信息并提交表单,该表单返回一些 html 作为响应。
生成的 html 显示在 jqModal div 内。然后,用户单击“关闭”以关闭模式对话框。
到目前为止,这一切都工作正常。
相反,我想要做的是关闭提交时的对话框,并使用服务器的响应更新 div。
调用代码:
<script type="text/javascript">
$(document).ready(function () {
$('#jqmWindowContainer').jqm({
modal: true,
ajax: '.... url to display my form ...',
onHide: myAddClose,
ajaxText: 'Loading',
toTop: true,
});
function myAddClose(hash) {
hash.w.fadeOut('300', function () { hash.o.remove(); });
}
});
</script>
调用页面的标记。单击“保存此搜索”会触发该对话框。
<a href="#" class="jqModal">Save this search</a>
<span id="jqmWindowContainer" class="jqmWindow"></span>
显示的表单:
<div class="jqmPopupForm" id="jqmPopupForm">
<div id="loadingMessage" style="display: none;">
Saving...
</div>
<% using (Ajax.BeginForm("Save", "AssetSearch",
new AjaxOptions()
{ HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
UpdateTargetId = "jqmPopupForm",
LoadingElementId = "loadingMessage"
}))
{%>
.... some html input elements go here ...
<input type="submit" value="Save Search" />
<a class="jqmClose" href="#">Cancel</a>
<%
}%>
</div>
现在,整个 jqmPopupForm div 正在被表单提交的结果替换。
如何关闭对话框并更新页面上的 div,而不是让用户关闭对话框?
Here's my scenario.
I call jqModal using its ajax functionality that displays a form in the modal dialog. The user fills out some information and submits the form which returns some html in response.
The resulting html is being displayed inside the jqModal div. The user then clicks Close to dismiss the modal dialog.
This all works correctly so far.
Instead, what I want to do is close the dialog on submit and update a div with the response from the server.
Calling code:
<script type="text/javascript">
$(document).ready(function () {
$('#jqmWindowContainer').jqm({
modal: true,
ajax: '.... url to display my form ...',
onHide: myAddClose,
ajaxText: 'Loading',
toTop: true,
});
function myAddClose(hash) {
hash.w.fadeOut('300', function () { hash.o.remove(); });
}
});
</script>
Calling page's markup. Clicking "Save this search" triggers the dialog.
<a href="#" class="jqModal">Save this search</a>
<span id="jqmWindowContainer" class="jqmWindow"></span>
Form that is displayed:
<div class="jqmPopupForm" id="jqmPopupForm">
<div id="loadingMessage" style="display: none;">
Saving...
</div>
<% using (Ajax.BeginForm("Save", "AssetSearch",
new AjaxOptions()
{ HttpMethod = "Post", InsertionMode = InsertionMode.Replace,
UpdateTargetId = "jqmPopupForm",
LoadingElementId = "loadingMessage"
}))
{%>
.... some html input elements go here ...
<input type="submit" value="Save Search" />
<a class="jqmClose" href="#">Cancel</a>
<%
}%>
</div>
Right now, the entire jqmPopupForm div is being replaced by the results of the form submit.
How can I close the dialog and update a div on the page instead of making the user dismiss the dialog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过向表单添加值为
$('#jqmWindowContainer').jqmHide();
的onSubmit
属性来关闭模式窗口。这应该允许在关闭模式时提交表单。更新:
在 ASP 代码的
ajaxOptions
部分中,添加属性onSuccess
并指定关闭模式窗口的函数。其中
closeWindow
是将关闭模式窗口的 JavaScript 函数的名称,并且validateForm
是 JavaScript 函数的名称,它将在提交之前验证表单。参考资料:
http://msdn.microsoft.com/en-us/library/dd460243.aspx
http://msdn.microsoft.com/en -us/library/system.web.mvc.ajax.ajaxoptions.aspx
You can close the modal window by adding an
onSubmit
attribute to the form with the value$('#jqmWindowContainer').jqmHide();
. That should allow for the submission of the form while closing the modal.UPDATE:
In the
ajaxOptions
portion of your ASP code, add the propertyonSuccess
and specify a function that closes the modal window.where
closeWindow
is the name of the JavaScript function which will close the modal window, andvalidateForm
is the name of the JavaScript function which will validate the form before submission.References:
http://msdn.microsoft.com/en-us/library/dd460243.aspx
http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions.aspx