JS中的迭代,JSON和回调

时间:2015-03-04 17:13:59

标签: javascript json callback jsonp yql

(使用Google Traductor翻译) 嗨,我正在学习javascript,而我正试图模拟yahoo finance页面上股票报价中发生的变化。

我正在阅读stackoverflow页面的许多回复,我这样做了。

http://js.do/code/53880 如果您使用的是谷歌浏览器,大约一分钟后就会出现控制台错误。 控制-Shift -J(控制台选项卡/错误)

错误: net :: ERR_INSUFFICIENT_RESOURCESjquery-1.9.1.js:8336 sendjquery-1.9.1.js:7978 jQuery.extend.ajaxVM8678:12 update

页面也滞后

$(function(){
$(function() {
	setInterval(update, 0);
});


function update() {
	var query = "select * from yahoo.finance.quotes where symbol = ";
	var symbolo = "'AAPL'"; 
	var yql = "http://query.yahooapis.com/v1/public/yql?q=" + escape(query+symbolo) + "&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback=?";
	var xhr2 = $.ajax({ 
		url: yql,
		jsonp: "myCallback",
		dataType: 'jsonp', 
		success: function(data) {
			var keys = data.query.results.quote;
			$("#a").html(keys.LastTradePriceOnly);			
		}, 
		error: function (xhr, ajaxOptions, thrownError) {
			alert("oth1"+xhr.statusText); 
			alert("oth2"+xhr.responseText); 
			alert("oth3"+xhr.status); 
			alert("oth4"+thrownError);
		}
	});
} 
});

1 个答案:

答案 0 :(得分:0)

setInterval(update, 0);

您尽可能快地生成Ajax请求。然后你的资源耗尽(可能在处理第一个请求之前)。

运行update函数一次,然后从setTimeout和{{1}内再次调用它(最好以success为基础的延迟)功能。

相关问题