1. <small id='qTKg0'></small><noframes id='qTKg0'>

    2. <i id='qTKg0'><tr id='qTKg0'><dt id='qTKg0'><q id='qTKg0'><span id='qTKg0'><b id='qTKg0'><form id='qTKg0'><ins id='qTKg0'></ins><ul id='qTKg0'></ul><sub id='qTKg0'></sub></form><legend id='qTKg0'></legend><bdo id='qTKg0'><pre id='qTKg0'><center id='qTKg0'></center></pre></bdo></b><th id='qTKg0'></th></span></q></dt></tr></i><div id='qTKg0'><tfoot id='qTKg0'></tfoot><dl id='qTKg0'><fieldset id='qTKg0'></fieldset></dl></div>
        <bdo id='qTKg0'></bdo><ul id='qTKg0'></ul>
      <legend id='qTKg0'><style id='qTKg0'><dir id='qTKg0'><q id='qTKg0'></q></dir></style></legend>
      <tfoot id='qTKg0'></tfoot>

      如何调试通过 AJAX(特别是 jQuery)加载的 Javascript

      How do I debug Javascript which was loaded via AJAX (specifically jQuery)(如何调试通过 AJAX(特别是 jQuery)加载的 Javascript)
        <tbody id='rKAA7'></tbody>

        <tfoot id='rKAA7'></tfoot>
          <i id='rKAA7'><tr id='rKAA7'><dt id='rKAA7'><q id='rKAA7'><span id='rKAA7'><b id='rKAA7'><form id='rKAA7'><ins id='rKAA7'></ins><ul id='rKAA7'></ul><sub id='rKAA7'></sub></form><legend id='rKAA7'></legend><bdo id='rKAA7'><pre id='rKAA7'><center id='rKAA7'></center></pre></bdo></b><th id='rKAA7'></th></span></q></dt></tr></i><div id='rKAA7'><tfoot id='rKAA7'></tfoot><dl id='rKAA7'><fieldset id='rKAA7'></fieldset></dl></div>
          <legend id='rKAA7'><style id='rKAA7'><dir id='rKAA7'><q id='rKAA7'></q></dir></style></legend>

            <bdo id='rKAA7'></bdo><ul id='rKAA7'></ul>

              <small id='rKAA7'></small><noframes id='rKAA7'>

              1. 本文介绍了如何调试通过 AJAX(特别是 jQuery)加载的 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我最近改变了我的编码风格,使用更复杂的项目来按需"加载页面(及其嵌入式脚本).但是,很难像加载这些脚本时那样调试它们:

                I have changed my coding style with more complex projects to loading pages (And their embedded scripts) "on demand" recently. However, it is difficult to debug those scripts as when they are loaded like:

                jQuery.get('/myModularPage', function(html){ /* insert the loaded page into the DOM */ });
                

                $('#some-container').load('/myOtherPage');
                

                这些脚本运行完美,但如果我在调试,如何在这些动态加载的页面和脚本中设置断点?

                These scripts run perfectly, but if I'm debugging, how can I set breakpoints in these dynamically loaded pages and scripts?

                推荐答案

                更新

                接受的表单现在带有 #(井号)而不是 @(符号)

                The accepted form is now with a # (hashtag) rather than @ (at symbol)

                语法已更改以避免与 IE 条件编译语句冲突和其他一些问题(感谢 Oleksandr Pshenychnyy 和 Varunkumar Nagarajan 指出这一点)

                The syntax was changed to to avoid conflicts with IE conditional compilation statements and some other issues (thanks to Oleksandr Pshenychnyy and Varunkumar Nagarajan for pointing this out)

                //#sourceURL=/path/to/file 
                

                这实际上可以是任何可以帮助您识别代码块的字符串.

                This can really be any string that helps you identify the block of code.

                JMac 的另一个优点:

                An additional good point from JMac:

                对我来说,js 文件显示在源列表中组称为(无域)".可能值得一提,因为我错过了一开始!

                For me, the js file was being displayed in the sources list within a group called "(no domain)". Might be worth mentioning as I missed it at first!

                原创

                在遇到 这篇文章.它确实非常适合我的开发环境(我写这篇文章时是 Chrome 22).

                I struggled with the above for about a week before running across this article. It really does work perfectly for my development environment (Chrome 22 as I write this).

                Firebug 还支持开发人员命名的 eval() 缓冲区:只需在 eval(expression) 末尾添加一行,例如:

                Firebug also supports developer-named eval() buffers: just add a line to the end of your eval(expression) like:

                //@ sourceURL=foo.js
                

                例如,给定这个简单的 html 文档:

                For example, given this simple html document:

                <!DOCTYPE html>
                <html>
                <body>
                    <p>My page's content</p>
                    <div id="counter"></div>
                    <script type="text/javascript">
                        //if this page is loaded into the DOM via ajax 
                        //the following code can't be debugged 
                        //(or even browsed in dev-tools)
                
                        for(i=0;i<10;i+=1) {
                            document.getElementById('counter').innerText = i;
                        }
                
                        //but if I add the line below
                        //it will "magically" show up in Dev Tools (or Firebug)
                
                        //@ sourceURL=/path/to/my/ajaxed/page
                    </script>
                <body>
                </html>
                

                我还没有发现的东西:

                • 是否必须为内联脚本的每个脚本块执行此操作?
                • 它必须是脚本块的最后一行吗?(这篇文章建议的答案是)

                这篇关于如何调试通过 AJAX(特别是 jQuery)加载的 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)

                <small id='UPBrv'></small><noframes id='UPBrv'>

                <i id='UPBrv'><tr id='UPBrv'><dt id='UPBrv'><q id='UPBrv'><span id='UPBrv'><b id='UPBrv'><form id='UPBrv'><ins id='UPBrv'></ins><ul id='UPBrv'></ul><sub id='UPBrv'></sub></form><legend id='UPBrv'></legend><bdo id='UPBrv'><pre id='UPBrv'><center id='UPBrv'></center></pre></bdo></b><th id='UPBrv'></th></span></q></dt></tr></i><div id='UPBrv'><tfoot id='UPBrv'></tfoot><dl id='UPBrv'><fieldset id='UPBrv'></fieldset></dl></div>
                  <tbody id='UPBrv'></tbody>
                <tfoot id='UPBrv'></tfoot>

              2. <legend id='UPBrv'><style id='UPBrv'><dir id='UPBrv'><q id='UPBrv'></q></dir></style></legend>

                        <bdo id='UPBrv'></bdo><ul id='UPBrv'></ul>