On my web page I have a jQuery UI Dialog. When I click the button (create new user) it opens a new window. My question is how can I open that window with an AJAX request?
在我的网页上,我有一个jQuery UI对话框。当我单击按钮(创建新用户)时,它会打开一个新窗口。我的问题是如何用AJAX请求打开该窗口?
It would be nice to open the dialog-form from another page. For example: dialog.html
从另一个页面打开对话框表单会很不错。例如:dialog.html
<div id="dialog-form" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<label for="password">Password</label>
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
You can see full code in this fiddle:
你可以在这个小提琴中看到完整的代码:
3 个解决方案
#1
10
You can define your dialog like this :
您可以像这样定义对话框:
function showUrlInDialog(url){
$.ajax({
url: 'dialog.html',
success: function(data) {
$("#dialog-form").load(data).dialog({modal:true}).dialog('open');
}
});
}
And define the current markup that is inside dialog-form div, into a new page called dialog.html. Call the above written function on the button click event. I hope this is what you needed.
并将dialog-form div中的当前标记定义到名为dialog.html的新页面中。在按钮单击事件上调用上述写入功能。我希望这就是你所需要的。
#2
6
I think this is a simpler version of the answer:
我认为这是一个更简单的答案版本:
$("#the-button").click(function(){
$("#dialog").dialog({modal: true}).dialog('open')).load("dialog.html")
})
#3
0
For me .load is not working. So I used,
对我来说.load不起作用。所以我用过,
function showUrlInDialog(url){
$.ajax({
url: 'dialog.html',
success: function(data) {
$("#dialog-form").html(data).dialog({modal:true}).dialog('open');
}
});
}
#1
10
You can define your dialog like this :
您可以像这样定义对话框:
function showUrlInDialog(url){
$.ajax({
url: 'dialog.html',
success: function(data) {
$("#dialog-form").load(data).dialog({modal:true}).dialog('open');
}
});
}
And define the current markup that is inside dialog-form div, into a new page called dialog.html. Call the above written function on the button click event. I hope this is what you needed.
并将dialog-form div中的当前标记定义到名为dialog.html的新页面中。在按钮单击事件上调用上述写入功能。我希望这就是你所需要的。
#2
6
I think this is a simpler version of the answer:
我认为这是一个更简单的答案版本:
$("#the-button").click(function(){
$("#dialog").dialog({modal: true}).dialog('open')).load("dialog.html")
})
#3
0
For me .load is not working. So I used,
对我来说.load不起作用。所以我用过,
function showUrlInDialog(url){
$.ajax({
url: 'dialog.html',
success: function(data) {
$("#dialog-form").html(data).dialog({modal:true}).dialog('open');
}
});
}