【发布时间】:2012-02-09 16:13:04
【问题描述】:
我正在尝试在 jQuery 脚本中从远程域(Zencoder 视频编码 API)检索 JSON 格式的数据。当脚本运行时,它返回代码 200,但 Firebug 在地址上显示错误(粗体红色突出显示,带有 X 的圆圈),并且响应为空。
这是与此相关的 jQuery 脚本:
var checkStatus = function(jobID) {
var url = 'https://app.zencoder.com/api/v2/jobs/' + jobID + '/progress.json?api_key=asdad3332d';
$.getJSON(url, function(data) {
if (data.state == 'processing') {
//Do things to indicate job is still going
//Repeat this function to check status again
setTimeout(function() {
checkStatus(jobID);
}, 6000);
} else if (data.state == 'finished') {
//Do some stuff
} else if (data.state == 'failed') {
//Show errors, do other stuff
}
});
};
这是一个返回的 JSON 示例。
{"outputs":[{"id":18492554,"state":"finished"},{"id":18492553,"state":"finished"},{"id":18492555,"state":"finished"}],"input":{"id":12437680,"state":"finished"},"state":"finished"}
最后,这是 Firebug 返回的响应头:
Response Headers
Cache-Control private, max-age=0, must-revalidate
Connection close
Content-Length 174
Content-Type application/json; charset=utf-8
Date Thu, 09 Feb 2012 16:06:13 GMT
Etag "48f2d50a838e0e1e433f7c0ba197e787"
Server ZenServer 0.1.0
X-Zencoder-Rate-Remaining 4999
任何帮助将不胜感激。在这个问题上摸不着头脑
文档 这是有关获取工作进度的 API 文档,这是我正在尝试做的。 https://app.zencoder.com/docs/api/jobs/progress
【问题讨论】:
-
好吧,你不能向外部域发出 Ajax 请求,它违反了同源策略。