06-jQuery-ajax请求
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-1.12.4.min.js"></script>
<script>
$(function(){
//查找元素
var $btn1 = $("#btn1")
var $btn2 = $("#btn2")
var $wenben = $("#wenben")
//设置点击事件
$btn1.click(function(){
//发送ajax的get请求 ......注意跨域问题
$.ajax({
url: "https://user.qzone.qq.com/proxy/domain/qzs.qzone.qq.com/qzone/v8/flash/headeditor/index.html",
type: "GET",
dataType: "json",
// data: {csid:1,page:1},
success: function(response,status){
console.log(response), //打印: 响应内容
console.log(status) //响应状态
}
});
});
//设置点击事件
$btn2.click(function(){
$.ajax({
url: "https://user.qzone.qq.com/proxy/domain/qzs.qzone.qq.com/qzone/v8/flash/headeditor/index.html",
type: "POST",
data: {pid:1},
success: function(response,status){
$wenben.html(response.msg); //给页面元素设置内容
},
error: function(response){
console.log(response)
}
});
});
});
</script>
</head>
<body>
<button id="btn1">发送get请求</button>
<button id="btn2">发送post请求</button>
<div id="wenben">
</div>
</body>
</html>
版权声明:本文为一只咸鱼测试原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。