• 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-08-25】连岳摘抄
    【2021-08-24】对意义的过度扭曲
    【2021-08-23】枕边语
    【2021-08-22】连岳摘抄
    【2021-08-21】旅历尚浅
    【2021-08-20】做事情,等对应好角色去思考
    索引缓冲对象(EBO或IBO )的理解
    vao, vbo的一点拙见
    兔队线段树
    「具体数学」二:和式
  • 原文地址:https://www.cnblogs.com/lvxisha/p/9751201.html
Copyright © 2020-2023  润新知