我想從jQuery腳本中的遠程域(Zencoder視頻編碼API)中檢索JSON格式的數據。當腳本運行時,它返回代碼200,但Firebug在地址上顯示錯誤(粗體紅色突出顯示,帶有X的圓圈),並且響應爲空。從遠程域檢索JSON,jQuery
這裏是與這個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"}
最後,這裏是由螢火蟲返回的響應頭:
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請求,它違反了同源策略。 – 2012-02-09 16:14:59