日期:2014-05-16 浏览次数:20409 次
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Mighty Gumball (Json)</title>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
</head>
<body>
<h1>Mighty Gumball Sales</h1>
<div id="sales">
<!-- 待显示的div -->
</div>
</body>
<script src="main.js"></script>
<!--<script src="http://gumball.wickedlysmart.com/?callback=updateSales"></script>-->
</html>
alert("memememem1231emmemem21312e!");
window.onload=function(){
alert("memememememmememe!");
setInterval(handleRefresh(),3000);
alert("memememememmememe!");
}
function handleRefresh(){
alert("1111111111111111111!");
var url="http://gumball.wickedlysmart.com/?callback=updateSales"+"&lastreporttime="+lastReportTime+
"&random="+(new Date()).getTime();
var newScriptElement=document.createElement("script");
newScriptElement.setAttribute("src",url);
newScriptElement.setAttribute("id",jsonp);
var oldScriptElement=document.getElementById("jsonp");
var head=document.getElementsByTagName("head")[0];/
if(oldScriptElement==null){
head.appendChild(newScriptElement);
}
else{
head.replaceChild(newScriptElement,oldScriptElement);
}
}
function updateSales(){
var lastReportTime=0;
var salesDiv=document.getElementById("sales");
for (var i = 0; i < sales.length; i++) {
var sale=sales[i];
var div=document.createElement("div");
div.setAttribute("class", "saleItem");
div.innerHTML=sale.name+" sold "+sale.sales +"gumballs";
salesDiv.appendChild(div);
};
if(sales.length>0){
lastReportTime=sales[sales.length-1].time;
}
}
var oldScriptElement=document.getElementById("jsonp");
var head=document.getElementsByTagName("head")[0];