ajax

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>读取文件</title>
</head>
<body>
	
	<input id="inp" type="text">
	<button id="btn">按钮</button>
	<div id="box">11</div>
	<script src="../../../../js/jquery-1.8.3.min.js"></script>
	<script>
		var btn = document.getElementById('btn');
		var box = document.getElementById('box');
		var inp = document.getElementById('inp');
		btn.onclick = function () {
			// body...
			box.innerHTML = '请求数据中,请稍后……';
			$.post('deve.json', {name: $('#inp').val()}, function(data) {
				alert('hellow');
				console.log(data.message[0].name);
				var aa = data.message[0].name;
				$('#box').html(aa);
			}).error(function() {
				/* Act on the event */
				$('#box').text("通信有问题");
			});
	}

	</script>
</body>
</html>

  deve.json数据为:

{
	"status":"0",
	"message":[
		{"name":"lxs","age":"22"}
	]
}

  或者请求的是PHP,txt,script格式

posted on 2018-10-10 16:14  婧星  阅读(138)  评论(0编辑  收藏  举报

导航