为什么我的jquery对话框ajax加载拉整个页面而不是选择器(div)?

时间:2012-03-27 19:32:02

标签: php javascript jquery ajax dialog

我遇到通过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和整个个人资料页面正在加载为什么?

1 个答案:

答案 0 :(得分:2)

你必须在“#”字符前加一个空格。

$dialog.load("/customer/profile #addressSel", ...

请注意,当您执行此操作时,在您加载页面片段并将其添加到DOM后,您选择的<script>中的<div>个标记将执行。< / p>