0
我正在使用flurry API來接收json數據。所以我不得不多次調用url來接收數據。但除了第一個請求,所有其他請求給這個錯誤Jquery ajax請求亂碼給出錯誤跨源請求被阻止
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
我創建jfiddle這一點。在那裏你可以看到相同的錯誤。
這裏是我使用收到的數據
function($) {
var url = 'http://api.flurry.com/appMetrics/ActiveUsersByMonth?apiAccessCode=DXGSYSYBSK26BZNSJB2X&apiKey=Removed&startDate=2012-01-01&endDate=2012-12-30&country=LK&versionName=1.0&groupBy=MONTHS';
$.ajax({
type: 'GET',
url: url,
crossDomain: true,
dataType: 'json',
success: function(json) {
console.dir(json);
alert();
},
error: function(e) {
console.log(e.message);
}
}).done(function(data) {
var activeUsers = [];
$.each(data.day, function(i, item) {
var arr = $.map(item, function(el) { return el; });
activeUsers.push(arr[1]);
});
var barChartData = {
labels : ["January","February","March","April","May","June","July","August","September","October","November","December"],
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data : activeUsers
}
]
}
var myChart = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData, {
responsive : true
});
});
})(jQuery);
http://jsfiddle.net/hydride/hv3xrjwL/
你試過數據類型: 'JSON' 到數據類型: 'JSONP', – 2014-10-02 02:19:52
是。沒有工作。我認爲jsonp不支持毛茸茸的api – Dushan 2014-10-02 02:21:29
然後使用PHP來請求服務並使用它來編碼成json。然後,您可以在Javascript中使用ajax訪問該json。 – 2014-10-02 02:26:18