【发布时间】:2012-03-30 16:35:57
【问题描述】:
我正在编写一个 Chrome 扩展程序,它执行一个简单的 ajax 调用(基于文档中的 this example):
$.ajax({
type: "GET",
url: "http://www.flags.99k.org/getFlags.php"
}).done(function(response) {
alert("SUCCESS: " + response);
}).fail(function(response) {
alert("FAILURE: " + response);
});
请求总是失败,因为警报显示:FAILURE: [object Object]。
URL 有效:当我在地址栏中输入http://www.flags.99k.org/getFlags.php 时,我得到了这个:
[{"UID": "1", "Message": "Hello"}, {"UID": "2", "Message": "World"}, {"UID": "3", "Message": "Hello World"}]
这是我的扩展名 manifest.json。
{
"name": "Hello World",
"version": "1.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://www.flags.99k.org/"
]
}
我使用 Chromium 17.0.963.79(Developer Build 125985 Linux)Ubuntu 11.10。
【问题讨论】:
-
JavaScript 代码是如何执行的?它看起来像injected。您使用的是哪个 Chrome 版本?
manifest.json的内容是什么? -
@MikeChristensen 我可以从错误函数中获得的信息不是很有帮助:
readyState: 0, responseText: "", status: 0, statusText: "error"... -
@RobW 代码的运行方式与
getstarted示例 (code.google.com/chrome/extensions/getstarted.html) 中的运行方式相同,来自我的default_popup页面头部的脚本标记。但我已经设法在 jsfiddle 中重现了这个问题(请参阅我的编辑)。
标签: ajax google-chrome jquery google-chrome-extension