一、Ajax
请求格式:
$.ajax({
type: , //请求的方式,get/post
url: , // 交给具体的哪个程序去处理
contentType: , //请求时的数据的类型 text html jpg json
data: , //请求时要携带的参数
dataType: , //服务器返回数据的类型 text html jpg json
success: function(data){ //请求成功后自动调用的
},
error: function(data){ //请求失败后自动调用的
}
})
测试:
$(function(){//文档就绪事件
$.ajax({ //发起Ajax请求数据
type: "POST",
url: "https://p.3.cn/prices/mgets",
contentType: "application/json;charset=utf-8",
data: { //拼接的参数
"skuIds": "J_100003717483"
},
dataType: "jsonp",
success: function(data) { //返回的结果
console.log(data);
},
error: function(data) {
console.log(data);
}
});
});