简体   繁体   English

我怎么弄清楚哪些其他JS文件干扰了我关注的一个?

[英]How do I figure out which other JS files are interfering with one I am concerned about?

I have a page that has a checkout from billing function - that basically triggers some JS. 我有一个checkout from billing功能checkout from billing的页面 - 基本上触发了一些JS。

You can view it here . 你可以在这里查看

Choose Blue & Small and add it to your cart. 选择蓝色和小巧并将其添加到您的购物车。

Then go to checkout. 然后去结账。

Enter some dummy data and press the 'copy from billing'. 输入一些虚拟数据,然后按“从结算复制”。 It won't work. 它不会起作用。 But, if you refresh the page and do the process again...it will work. 但是,如果您刷新页面并再次执行该过程......它将起作用。

Also, you will notice that in the first go around, the 'shipping method' dropdown doesn't work. 此外,您会注意到,在第一次出现时,“送货方式”下拉列表不起作用。 But, once you refresh, it does. 但是,一旦你刷新,它确实。

I tried the JS responsible for this functionality in the console and it works fine, on the first load. 我尝试在控制台中负责此功能的JS,并且它在第一次加载时工作正常。 So I know the code is right (all the fields it is trying to select are right, etc.). 所以我知道代码是正确的(它试图选择的所有字段都是正确的,等等)。

How on earth do I debug this? 我该如何调试呢?

I was able to verify the behavior on your site, and get it to work on the first load of the page, with one small tweak. 我能够验证您网站上的行为,并通过一个小的调整让它在第一次加载页面时工作。 I think the order of loading is at the heart of the issue. 我认为装载的顺序是问题的核心。

I was able to get it to work by rerunning the first line from your piggyback.js file after the page had loaded. 我可以通过在页面加载后重新运行piggyback.js文件中的第一行来使其工作。

Here is a quick screencast showing the issue and quick fix. 这是一个快速的截屏视频,显示问题和快速修复。

If you could have this part run at the end of the load, I think that would fix it for you. 如果你可以在负载结束时运行这个部分,我想这会为你解决。

UPDATE 1: You might also turn off turbolinks on the 'Proceed to Checkout' button. 更新1:您也可以在“继续结账”按钮上关闭turbolinks。 When I added data-no-turbolink="true" to the link, then clicked, the page was not turboloaded, but loaded as a full page refresh. 当我向链接添加data-no-turbolink =“true”,然后单击时,页面不是涡轮增压,而是作为整页刷新加载。 Then the copy shipping functionality worked as expected. 然后,复制传送功能按预期工作。

UPDATE 2: The real issue is most likely that your js code isn't triggering because it only expects a dom ready event. 更新2:真正的问题很可能是你的js代码没有触发,因为它只需要一个dom ready事件。 You might be able to trigger it when turbolinks loads it, using a page:load event, as described here . 您可以在turbolinks加载它时使用页面:load事件触发它, 如此处所述

So this is what is happening... 所以这就是发生的事情......

On the cart page, http://apt-605.herokuapp.com/checkout/cart where you have the Proceed to Checkout Button, there is some javascript that is hooking onto all anchor tags, making an ajax request with the anchor tag's href and then replacing the content of the document with the content received from the ajax call. 在购物车页面上, http://apt-605.herokuapp.com/checkout/cart ,你有Proceed to Checkout按钮,有一些javascript挂钩到所有锚标签,使用锚标签的href进行ajax请求然后用从ajax调用接收的内容替换文档的内容。

What this is doing, is that the new content does not load like a new page, the head is never rendered, and the piggybak js is never loaded. 这是做什么的,新内容不会像新页面一样加载,头部永远不会被渲染,并且从不加载piggybak js。

You can verify this, keep firebug open, switch to net tab, on the cart page. 您可以验证这一点,保持firebug打开,切换到购物车页面上的网络标签。 Now when you click on Proceed to checkout, you'll notice an XHR request is made to get checkout , and the checkout page loads without the net tab refreshing. 现在,当您单击继续结帐时,您会注意到XHR请求以获取checkout ,并且加载结帐页面时不会刷新网络选项卡。 You will also not see the puiggybak js loading in the net tab. 您也不会在网络标签中看到puiggybak js加载。

So basically you have to figure out what js you are using on your cart page that is attaching itself to all anchor tags, my guess would be a library that gives ajaxified navigation out of the box. 所以基本上你必须弄清楚你在购物车页面上使用的js是什么,它将自己附加到所有锚标签上,我猜这将是一个开箱即用的开放式导航库。

Hope this helps. 希望这可以帮助。

Are you ajaxing in the content? 你在内容中喋喋不休吗?

You're head is missing 你头脑不见了

<script src="/assets/piggybak/piggybak-application-1d1707f6934602bfae8e3a33d27a4a9b.js" type="text/javascript"></script>

javascript file on first load of page. 第一次加载页面时的javascript文件。

I agree with @Austin 我同意@Austin

The script <script src="/assets/piggybak/piggybak-application-1d1707f6934602bfae8e3a33d27a4a9b.js" type="text/javascript"></script> 脚本<script src="/assets/piggybak/piggybak-application-1d1707f6934602bfae8e3a33d27a4a9b.js" type="text/javascript"></script>

is not getting called when you load the page at first, when you reload the page this link is inserted there dynamically, you must have written some code to handle that, If possible reveal that code so that we can help you further... 首先加载页面时没有调用,当你重新加载页面时,这个链接是动态插入的,你必须编写一些代码来处理它,如果可能的话显示代码,这样我们就可以帮助你了...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该怎么做:将所有 js 文件导入 html 或找出我需要从 bootstrap 崩溃的 js 文件才能工作? - How do I either: import all of the js files into html or figure out which js files I need to get collapse from bootstrap to work? 我正在尝试通过复选框从数组中删除多个元素我正在使用 vue.js 但我无法弄清楚该怎么做 - I am trying to delete multiple elements from an array through checkbox i am using vue.js but i am unable to figure out how to do it 如何让Turbolinks停止干扰我的JS? - How do I get Turbolinks to stop interfering with my JS? 我是node.js的新手,并试图弄清楚异步回调是如何工作的 - I am new to node.js and trying to figure out how asynchronous call back work 我试图弄清楚如何让我的函数一个接一个地运行……但是它不起作用 - I am trying to figure out how to make my functions run one after another… but it is not working 我正在尝试导出一个函数以导入到另一个 javascript 页面,但无法弄清楚如何使用导出/导入来做到这一点 - i am trying to export a function to import into another javascript page but can not figure out how to do it with exports/imports 所以,我正在处理这个项目,其中包含许多带有 html、css 和 js 文件的子文件夹,我如何开始浏览器同步? - so, I am working on this project which includes lots of subfolders with html ,css and js files, How do i start browser sync? IE7:“脚本运行缓慢,您要停止它吗?”-如何确定脚本是哪个? - IE7: “Script is running slowly, do you want to stop it?” - How can I figure out which script it is? 我如何找出哪个Javascript代码定期挂在浏览器上? - How do I figure out which Javascript code is periodically hanging the browser? 我正在使用jQuery提出几个对JSONP数据的请求,如何确定哪个请求会得到哪个结果? - I'm making several requests for JSONP data using jQuery, how do I figure out which request goes with which result?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM