基于jq和纯js的 读取本地.txt文件的方法

时间:2025-04-08 12:25:50

好像ajax本来就可以读到.txt

 

<!DOCTYPE HTML>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>读取txt文件</title>
	</head>

	<body>
		<script src="/jquery/2.2.4/"></script>
		<script>
			$.ajax({
				url: "",
				success: function(data, status) {
					(arguments)
					(data)
				},
				error: function(data, status) {
					(arguments)
				}
			});

			/**/

			function readTxt() {
				var xhr = new XMLHttpRequest();
				("get", "", true);
				();
				 = function() {
					if( == 4 &&  == 200) {
						(xhr);
						();
					} else if( == 404) {
						();
					}
				};
			}
			readTxt()
		</script>
	</body>

</html>