托管该网站后,外部Javascript库不起作用 [英] External Javascript library doesn't work after hosting the site
问题描述
我在这里有一个奇怪的bug。我有一个简单的网站( http://davidpuetter.azurewebsites.net/shop.html# )应该加载JQuery库和EasyUI库。 JQuery似乎加载得很好,因为我有一个函数在页面加载时打印出ready。预期的功能是,我可以将在那里看到的每个产品拖到右侧的购物车上。如果我从我的计算机手动运行html文件,但没有托管它,则此作品完全正常。
I have a bit of an odd bug here; I have a simple website (http://davidpuetter.azurewebsites.net/shop.html#) that is supposed to load the JQuery library, and the EasyUI library. The JQuery seems to load just fine, because I have a function to print out "ready" when the page is loaded. What the intended function is, is that I can drag each product seen there onto the shopping cart to the right. This works perfectly fine if I run the html files manually from my computer, but not since it has been hosted.
这里发生了什么?
谢谢对于任何帮助
What's happening here?
Thanks for any help
推荐答案
在 scripts / shop.js
你正在调用 $(#shop)。load(shopcontent / cat1.html);
,但是当你运行 $(。item)。draggable({
on line 27。
On line 7 in scripts/shop.js
you are calling $("#shop").load("shopcontent/cat1.html");
, but it has not loaded yet when you run $(".item").draggable({
on line 27.
执行该行时,没有该类的元素 item
。
When that lines is executed there are no elements with the class item
in the document.
我的猜测是 $(#shop) .load(..
在 file://
中运行时是同步的)。在线路加载时显然不同步。
My guess is that $("#shop").load(..
is synchronous when running in file://
. It is obviously not synchronous when loading over the wire.
在调用 .draggable $ c之前,您应该等待
.load
完成(回调) $ c>。请参阅文档。
You should wait for .load
to complete (callback) before you call .draggable
. See docs.
这篇关于托管该网站后,外部Javascript库不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!