这篇文章主要介绍了关于jquery-ajax请求json数据并加载在前端页面,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
Ajax技术应用广泛,这种异步加载技术,无需刷新网页即可更新网站内容,全局或者局部均可,所以大家应该学会这种技巧,把技术用上来。
{ "title":"Segmentfault", "url":"https://segmentfault.com" }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>jQuery - Ajax - Json</title> <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(function(){ $("button").click(function(){ $.ajax({ type:"GET", url:"demo.json", dataType:"json", success:function(data){ $("#title").text(data.title); $("#url").text(data.url); } }) }) }) </script> </head> <body> <button name="button" type="button">加载数据</button> <h2>title:<span id="title"></span></h2> <h2>url:<span id="url"></span></h2> </body> </html>
页面中需要引入jQuery库
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
立即学习“前端免费学习笔记(深入)”;
以上就是jQuery-Ajax请求Json数据并加载在前端页面的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号