<!DOCTYPE html>
<html>
<head>
	<title>AJAX Example</title>
</head>
<body>
	<h1>Stock Quote</h1>
	<input type="text" id="stockCode" placeholder="Enter stock code">
	<button onclick="getStockQuote()">Get Quote</button>
	<div id="stockQuoteDiv"></div>
	<script>
		function getStockQuote() {
			var stockCode = document.getElementById("stockCode").value;
			var url = "http://qt.gtimg.cn/q=" + stockCode;
			var xhr = new XMLHttpRequest();
			xhr.open("GET", url, true);
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					var response = xhr.responseText;
					var stockInfo = response.split("~");
					var table = "<table><tr><th>Code</th><th>Name</th><th>Price</th><th>Yesterday</th><th>Today</th><th>Volume</th></tr>";
					table += "<tr><td>" + stockInfo[2] + "</td><td>" + stockInfo[1] + "</td><td>" + stockInfo[3] + "</td><td>" + stockInfo[4] + "</td><td>" + stockInfo[5] + "</td><td>" + stockInfo[36] + "</td></tr></table>";
					document.getElementById("stockQuoteDiv").innerHTML = table;
				}
			};
			xhr.send();
		}
	</script>
</body>
</html
写一个ajax代码1、要求: 1设计一个简单用户界面上面一个文本框后面跟一个查询按钮 2用户输入股票代码并点击查询后调用跨域接口查询股票的实时行情信息在文本框下面用表格简单显示该股票的代码、名称、当前价格、昨收、今开和成交量手信息 3使用接口httpqtgtimgcn

原文地址: https://www.cveoy.top/t/topic/dCoq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录