利用Ajax读取文件并转化为数组

前端之家收集整理的这篇文章主要介绍了利用Ajax读取文件并转化为数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SDM2Cast</title>

<!-- CSS Files -->
<link type="text/css" href="base.css" rel="stylesheet" />
<link type="text/css" href="Other.css" rel="stylesheet" />

<!--[if IE]><script language="javascript" type="text/javascript" src="../../Extras/excanvas.js"></script><![endif]-->

<!-- JIT Library File -->
<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) {// code for IE7+,Firefox,Chrome,Opera,Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6,IE5 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

猜你在找的Ajax相关文章