- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我无法开始工作的 jquery 片段。我试图通过 jsonpCallback 调用 blackBackground()
$(document).ready(function()
{
function blackBackground(data, status)
{
console.log("black background");
//I want to eventually change the body style to black
}
$.ajax({
url: 'http://localhost:3000/someurl',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: 'blackBackground'
});
});
更新:
jsonpCallback: 'blackBackground'
至
jsonpCallback: blackBackground
同时将 blackBackground 移至全局范围。感谢大家的回复。
最佳答案
这里的问题是函数 blackBackground
在全局范围内不可用。
您可以通过如下声明来在全局范围内公开该函数:
window.blackFunction = function(){ .. }
...或者在ajax配置中使用匿名函数:
jsonpCallback: function(result){ .. }
我推荐后者,因为它会让你的全局范围保持整洁的时间更长一点:)
关于jquery - jsonpCallback 未调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15347201/
这是我无法开始工作的 jquery 片段。我试图通过 jsonpCallback 调用 blackBackground() $(document).ready(function() { fun
更新1: 我刚刚从 jquery 1.4.4 升级到 1.6.1。这对原始问题中的脚本有何影响? 原始问题: 正如我测试的那样,我做了: $(document).ready(function() {
我想在 while 或 for 循环中调用 jsonpcallback 函数。但我得到了异步结果。如何在 jsonpcallback 中实现这一点。请任何人帮我解决这个问题或提供任何其他解决方案。 w
我在 URL 中使用不同的路径和查询对相同的 API 进行了不同的 Ajax 调用,但是使用相同的 jsonpCallback 我无法更改 当我调用一个 Ajax url - 一切正常! 但是当我需要
在向地理服务器发出请求时,我收到“parseResponse”不是一个函数。我尝试了几种方法来解决这个问题,但结果仍然是:“parseResponse不是一个函数” 我尝试在获取中设置同步选项,我尝试
我正在使用 Netflix 的 OData API 开发一个应用程序。我关注了Stephen Walther's blog entry关于如何查询 OData API。在其中,他使用了以下代码: $.
我在静态文件服务器 - GitHub Pages 上提供 JSONP JavaScript 文件。 这意味着我无法动态在服务器上设置 JSONP 回调函数名称... Dynamic example -
我是一名优秀的程序员,十分优秀!