lvxisha

ajax请求json中的数据

在这里不多说,直接可以运行代码看效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="../css/layer.css">
	<script src="jquery-1.8.3.min.js"></script>
</head>
<body>
	<input type="text" id="ipt">
	<button id="btn">点击</button>
	<script src="layer.js"></script>
<script>
	document.getElementById(\'btn\').onclick = function() {
		// layer.msg(\'hello word\');
		var ipt = document.getElementById(\'ipt\').value;
		
		if (!ipt) {//若input的value值为空,则弹出内容
			layer.open({
				title:\'提示\',
				content:\'输入验证码\',
				skin: \'demo-class\'
			});
			return;//结束函数体
		}
		$.ajax({
			url: \'../pages/admin/view/login/login.json\',
			type: \'post\',
			dataType: \'json\',
			data: {
				ipt: \'ipt\'
			},
			success:function(res){
				layer.msg(\'提交成功\',{icon:1});
				console.log(res);
			}
		})	
	}
</script>

</body>
</html>

  在这里请求的json数据,内容为:

code----表示服务器端传递的状态,即状态为0时,信息为message

{
	"code":"0",
	"message":"hahah"
}

 相关文件下载,可直接运行查看效果;链接:https://pan.baidu.com/s/17YkdIF9UQHyt_8RrrliRFw 密码:lc71 

分类:

技术点:

相关文章:

  • 2021-05-02
  • 2021-12-16
  • 2021-11-20
  • 2022-12-23
  • 2021-07-29
  • 2021-08-26
  • 2021-12-04
猜你喜欢
  • 2022-02-01
  • 2021-12-31
  • 2021-11-04
  • 2021-11-25
  • 2021-12-07
  • 2021-10-10
  • 2021-11-27
相关资源
相似解决方案