jQuery-Ajax请求Json数据并加载在前端页面,附视频教程讲解!
Ajax技术应用广泛,这种异步加载技术,无需刷新网页即可更新网站内容,全局或者局部均可,所以大家应该学会这种技巧,把技术用上来。
创建demo.json文件,用来做数据源:
{
"title":"Segmentfault",
"url":"https://segmentfault.com"
}创建index.html文件,前端页面并加载数据
<!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库
视频教程:https://pan.baidu.com/s/1vpfT...
相关推荐
chongxiaocheng 2020-08-16
ppsurcao 2020-06-14
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
时光如瑾雨微凉 2020-07-19
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05