问题标签 [getscript]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - JavaScript - 加载脚本顺序
我正在为 Android 操作系统开发一个 HTML+JavaScript 应用程序。在 HTML 页面中,我正在加载另一个具有以下代码的 JS 文件:
在 HTML 页面上,我正在循环浏览地图。问题是,在我的应用程序第一次加载时,一切正常。但是当我打开其他应用程序或只是返回然后我恢复我的应用程序时,地图的长度等于零。(我认为这与HTML页面加载其依赖项的顺序有关,但我不知道如何解决这个问题......)有
什么建议吗?谢谢!
在我的 JSFile.js 中编辑
我的 JS 代码:
我在 HTML 页面中的 JS 代码:
实际结果是,在第一次加载应用程序时,一切都运行良好 - 我收到“嗨”警报。但是当应用程序恢复时 - 我什么也没得到。
jquery - 如何将本机 JavaScript 添加到`$.when`?
如何将本机 javascript 添加到 中$.when
?当我想为每个 inside 使用时,我在下面执行此操作时出现错误$.when
。有任何想法吗?
jquery - Injecting data into jQuery $.getScript call
I need to inject some extra data into $.getScript
call, so it'll be availabe in ready handler, how do I do that?
in regular event handlers I can do do by passing the data as a second parameter and get it by e.data.* from within the event handler:
which doesn't seem to work with $.getScript.
ruby-on-rails - getScript jQuery path not working / Ruby on Rails
I've got a jQuery function that is called after a doubleclick on a list item.
app/assets/javascripts/tile/tile.js
Next to applying some new formats to said item my main goal is to make a database entry from my like
controller. In this Railscast the index
action from their comments
controller gets called with this simple line.
Additionally some JavaScript gets called from a index.js.erb
file.
My first problem with understanding the example code from Railscasts is how they define the action. If I wanted to call the action createLike
from my likes_controller
how would I call it?
Secondly, my attempts so far have all failed because both the JavaScript file doesn't load and the action doesn't get called aswell.
Somehow I sense that I've messed up with the paths. Where should I locate the JavaScript files that should get called with the getScript
function?
Files
app/assets/javascripts/likes/index.js.erb
app/controllers/likes_controller.rb
javascript - 如何停止 $.getScript() 错误消息?
我只是调用$.getSCript(location.href)
它并正确获取脚本,但是如果文件不存在(这就是我打算做的很多事情)它会打印一个错误GET (url) 500 (Internal Server Error)
如何防止这种情况发生?如何摆脱错误信息?
jquery - jQuery getScript() 无法解析
我正在使用 jQuerygetScript()
加载单独的 javascript 文件。这些文件似乎加载得很好(我知道这是因为当我输入了一个不正确的 URL 时,它会抛出一个错误 - 正确的 URL 没有错误)。
但是,该done()
功能似乎不起作用。控制台不会记录“完成”,也不会调用任何函数。
jquery - jQuery getScript 执行脚本后调用代码
我们到处使用 $.getScript(url, callback) 。在排除非常偶然的未定义错误时,我从 jQuery 文档中注意到了这一点:
“一旦脚本被加载但不一定执行,回调就会被触发。”
谁能建议一种通用方法来保证在脚本执行后调用回调?
我知道我可以轮询一个在脚本中定义的 var,但我希望有一个更优雅的解决方案(因为我必须在数百个位置为数百个不同的变量进行这种更改)......就像一个我错过了文档中的回调。
提前致谢!
javascript - 在一遍又一遍地删除 HTML 之后,使用 JQuery 的 getScript 多次加载 HTML
我有一个用 HTML/JavaScript/JQuery/CSS 编写的 SPA(单页应用程序)
每次单击导航链接时,主 div 都会通过 ajax 命令加载一大块 HTML/JavaScript/JQuery/CSS,并且 getScript 函数用于加载该块的 JavaScript/JQuery 部分。
一旦用户点击另一个链接,主 div 就会通过 remove() 函数被删除,并且带有其 JavaScript/Jquery 的新块将替换它。
这是问题所在:当我在第二次、第三次等时间加载主 div 的内容时(如果用户点击另一个链接但又回到这个链接)我是否再次运行 getScript 函数来加载 JavaScript/查询?如果是这样 - 它不会将“on”和其他事件相互绑定,还是 remove() 函数会处理它并且没有任何内存泄漏是安全的?
谢谢您的反馈!
jquery - 内部的图像滑块(ajax).load 中断
这是我在这个论坛上的第一个问题,它与 ajax 中的 .load 元素有关。基本上我有一个无序列表,其中列表项是可点击的链接:
单击这些链接时会加载不同的 html 片段,其中一些包含图像滑块(主页和项目链接)。这些在第一次请求内容时加载正常,但是如果您导航到另一个选项卡然后返回滑块不再起作用。使用 ajax 方法的代码位于 $.(document).ready 函数中,如下所示。
我完全不知道如何解决这个问题,尝试了不同的方法。我知道脚本加载是因为我得到了 projectview ok 警报,但不知何故,图像滑块上的导航中断了。
有没有人以前见过这个错误并且可以提供帮助?
附带说明:如果有人知道如何使用 .load ajax 方法获得后退按钮功能,那也将不胜感激。
jquery - 在 done() 中嵌套第二个 $.when()
“是否可以将第二个 $.when().done() 嵌套在另一个 $.when().done() 中。它有时似乎有效,但并非始终如一。问题似乎是第二个 done()并不总是触发。我在下面提供了一个我正在尝试做的示例。