查看源代码时,附加数据似乎不在标记中

发布于 2024-08-14 06:47:25 字数 2323 浏览 3 评论 0原文

我有一个网站,上面有一些 AJAX,基本上用户点击一个链接,一些 AJAX 会触发一个返回一些 HTML 的方法,如下所示,正如标题所说,返回的数据似乎没有进入HTML,这就是我的手风琴没有被制作的原因吗?这很奇怪,因为结果被返回,因为它们输出到我的屏幕上。

$(document).ready(function() {
    // hides the main_menu as soon as the DOM is ready
    // (a little sooner than page load)
    $('#main_menu').hide();
        // shows the slickbox on clicking the noted link  
        $('h3#show-menu a').click(function() {
                $('#main_menu').toggle('slow');
                    return false;
        });
//try and hide the left content when it is null
    $("#left-content:empty").hide();
    //style up the scroll bar
        $('#left-content').jScrollPane();

        //do some AJAX to call the method instead of the browser
        $("a.navlink").click(function (ev) {
            $(this).toggleClass("active");
            ev.preventDefault();
            var id = $(this).attr("id")
            if ($(this).hasClass("active")) {
               $("."+id).remove();
            }
            else {  
            //$(this).toggleClass("active");
                  var url = $(this).attr("href");
                    $.ajax ({
                        url:  url,
                        type: "GET",
                        success : function (html) {
                            $("#accordion").append(html);
                            $('#accordion').accordion({
                                active: 0,
                                header:'h2'
                            });
                            //alert(accordion())
                        }
                    });
            }
        });
  });

我确信您可以从代码中收集到,返回的 HTML 被附加到

我注意到,当我查看源代码时,无论 AJAX 是否已触发,

即使我可以看到返回的数据,我怎样才能让手风琴工作?

=======AJAX 返回的内容======

?php
if(isset($content)) {
//  var_dump($content);
    foreach($content as $row) {
        print "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
        print "<div class='$row[category_name]'>$row[content_title]</div>";
    }
}
?>

=========AJAX html 的去向=========

    <div id="right-content">
    <div id="accordion"></div>
</div>

I have a website with some AJAX on it, basically the users clicks on a link, and some AJAX goes and fires a method that returns some HTML as show below, as the title says the data that is returned does not seem to be going into the HTML, is this why my accordions are not being made? It is strange becuase results are being returned because they out put onto my screen.

$(document).ready(function() {
    // hides the main_menu as soon as the DOM is ready
    // (a little sooner than page load)
    $('#main_menu').hide();
        // shows the slickbox on clicking the noted link  
        $('h3#show-menu a').click(function() {
                $('#main_menu').toggle('slow');
                    return false;
        });
//try and hide the left content when it is null
    $("#left-content:empty").hide();
    //style up the scroll bar
        $('#left-content').jScrollPane();

        //do some AJAX to call the method instead of the browser
        $("a.navlink").click(function (ev) {
            $(this).toggleClass("active");
            ev.preventDefault();
            var id = $(this).attr("id")
            if ($(this).hasClass("active")) {
               $("."+id).remove();
            }
            else {  
            //$(this).toggleClass("active");
                  var url = $(this).attr("href");
                    $.ajax ({
                        url:  url,
                        type: "GET",
                        success : function (html) {
                            $("#accordion").append(html);
                            $('#accordion').accordion({
                                active: 0,
                                header:'h2'
                            });
                            //alert(accordion())
                        }
                    });
            }
        });
  });

As I am sure you can gather from the code, the returned HTML is appended to the <div id="accordion> and then it is 'turned' into an accordion, however this is not happening, all I get are the classes getting added to the div that would give accordion functionality but I get no real functionality.

I noticed that when I view source whether or not the AJAX has fired there is no content in <div id="accordion> even though I can see the returned data, how can I get the accordion to work?

=======What gets returned by the AJAX======

?php
if(isset($content)) {
//  var_dump($content);
    foreach($content as $row) {
        print "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
        print "<div class='$row[category_name]'>$row[content_title]</div>";
    }
}
?>

=========Where the AJAX html goes=========

    <div id="right-content">
    <div id="accordion"></div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋凉 2024-08-21 06:47:25

查看源代码显示您的机器下载的文件的源代码,即。任何 AJAX 更改之前的文件。无论您在 Javascript 中做什么,查看源代码都不会发生任何变化(当然,除非您转到新页面)。

如果您想查看当前 DOM 如何查找您的页面,您需要使用 Firebug 或 IE Developer 工具栏等工具。

View source shows the source code of the file your machine downloaded, ie. the file BEFORE any AJAX changes. No matter what you do in Javascript, nothing will ever change in view source (unless of course you go to a new page).

If you want to see how the current DOM looks for your page, you need to use a tool like Firebug or the IE Developer toolbar.

忆梦 2024-08-21 06:47:25

实际上,您不需要 Firefox 中的 Firebug,但 Firebug 是一个很棒的工具。选择您认为应该更改的字段,右键单击并选择“查看选择源”(仅限 Firefox)。

Actually you don't need Firebug from Firefox but firebug is a fantastic tool.. Select the field you think should change, right click and select "View Selection Source" (Firefox only).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文