前端之家收集整理的这篇文章主要介绍了
利用Ajax读取文件并转化为数组,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SDM2Cast</title>
<link type="text/css" href="base.css" rel="stylesheet" />
<link type="text/css" href="Other.css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="jit.js"></script>
<script language="javascript" type="text/javascript" src='jquery-2.1.1.min.js'></script>
<script language="javascript" type="text/javascript" src="animate.js"></script>
<script language="javascript" type="text/javascript" src="plotNode.js"></script>
<script language="javascript" type="text/javascript" src="main.js"></script>
<script language="javascript" type="text/javascript"> setInterval(function(){ getStr(); },5000) </script>
</head>
<body onload="onload()">
<script> function onload(){ getStr(); } </script>
<script type="text/javascript"> function getStr() { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","testpair.txt",true); xmlhttp.send(); } function getpair(){ var str = document.getElementById("myDiv").innerHTML; document.write(str); var pair=str.split("|"); for(var i=0;i<pair.length;i++) { document.write(pair[i]); } } </script>
<div id="myDiv"></div>
<script> $("#myDiv").hide(); </script>
<button type="button" onclick="getpair()">getpair</button>
</body>
</html>
原文链接:https://www.f2er.com/ajax/163144.html