总结:
1.$.get $.post 使用类似,都是默认异步请求。$.get(url,[data],[callback]),$.post(url,[data],[callback],[type]),type为请求 的数据类型,可以是html,xml,json等类型,如果我们设置这个参数为:json,那么返回的格式则是json格式的,如果没有设置,就 和$.get()返回的格式一样,都是字符串的
$.get( “url”, function(data){
var data = JSON.parse(data), result = data.result;
console.log(data);
})
var postData = {
"schoolGUID": schoolguid,
"subjectName": subjectName,
"courseName": courseName,
"voiceBroadcastCode": voiceBroadcastCode,
"voiceBroadcastDesc": voiceBroadcastDesc
};
$.post( window.web.host + "voiceBroadcast/voiceBroadcastBatchCreate", postData, function(data){
var data = JSON.parse(data);
2. ajax同步请求
async:false同步请求,注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行
$.ajax({
url: 'https://pcs.baidu.com/rest/2.0/pcs/device',
async:false,
type: "get",
data: {
method: "vod",
shareid: shareid,
uk: uk,
st: startStamp,
et: endStamp
},
success: function (data) {
$("#video").attr("src", data["src"]);
},
error: function (XMLHttpRequest, textStatus, errThrown) {
tip("获取视频播放地址失败");
}
})