我遇到通过jquery ajax加载调用加载我的选择器的问题,见下文: -
var $loading = $ ('<img src="/img/loading.gif" alt="loading">');
$("#addAddressBtn").click(function(){
var $dialog = $('<div></div>')
.append($loading.clone());
$dialog.load("/customer/profile#addressSel", [], function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$dialog.html(msg + xhr.status + " " + xhr.statusText);
}
else{
$dialog.dialog({
title: "Add Address",
width: "auto",
height: "auto",
modal: "true"
});
$dialog.dialog('open');
return false;
};
});
});
我想在对话框中显示的是addresssSel div和整个个人资料页面正在加载为什么?
答案 0 :(得分:2)
你必须在“#”字符前加一个空格。
$dialog.load("/customer/profile #addressSel", ...
请注意,当您执行此操作时,在您加载页面片段并将其添加到DOM后,您选择的<script>
中的<div>
个标记将不执行。< / p>