错误的回调函数字符串

时间:2016-01-10 18:48:26

标签: javascript ajax api jsonp

我使用此代码属于绘制货币更改值,但绘制图表时出现问题。

$(document).ready(function () {
	localhost1 = {}; //our global namespace variable
	localhost1.chg_percent = [];
	localhost1.currency =[];
	localhost1.chart1 = {yAxisMin : null, yAxisMax : null }; //this object holds things belonging to this chart1
	
	var url1 = 'http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&view=basic';
	$.ajax({
		url: url1,
		cache: false,
		dataType: 'jsonp',
		context: localhost1,
		success: function(data) {
		for(var i=0; i<data.list.resources.length; i++)	{
			this.currencyObj = data.list.resources[i].fields;
			this.chg_percent.push(parseFloat(data.list.resources[i].resource.fields.chg_percent));
			this.currency.push(data.list.resources[i].resource.fields.name);			
		}
		this.chart1.yAxisMax = (function(array){
			var number_array = [];
			
			for(var i=0; i<array; i++){
				if(array[i] != null){
					number_array.push(array[i]);
				}
			}
			return math.max.apply(Math, number_array);
		})(this.chg_percent);
		this.chart1.yAxisMin = (function(array){
			var number_array = [];
			
			for(var i=0; i<array; i++){
				if(array[i] != null){
					number_array.push(array[i]);
				}
			}
			return math.min.apply(Math, number_array);
		})(this.chg_percent);
		
	this.chart1.data.series[0].data = this.chg_percent;
	this.chart1.data.xAxis.categories = this.currency;
	chart = new Highcharts.Chart(this.chart1.data);
	console.log(data);
	}
	});
    localhost1.chart1.data = {
        chart: {
        	renderTo: 'container',
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: <a href="https://finance.yahoo.com">Source : yahoo</a>'
        },
        xAxis: {
            categories: null,
            title: {
                text: null
            }
        },
        yAxis: {
            min: localhost1.chart1.yAxisMin,
            max: localhost1.chart1.yAxisMax,
            title: {
                text: 'Daily Percentage Change',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
        	formatter: function(){
        		return ''+
        		this.series.name +': '+ this.y +' %';
        	}
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -1,
            y: 1,
            floating: true,
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Daily Change',
            data: null
        }]
  };     
  
});

当我运行此代码时,我在控制台中收到一条错误消息“不可接受:http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json&view=basic&callback=jQuery18203581249208157574_1452451202663&_=1452451202773”。

虽然我使用的API是正确的,但回调函数返回的字符串似乎是不正确的。

0 个答案:

没有答案