1.JQ发ajax请求:
//第一种请求方式(post发jason请求)
var data= {
"fd_project_name": "",
"fd_total_size": "",
"ip_phase": ""
}
$.ajax({
type: "POST",
url: "http://172.16.7.156:8080/cswadi-search/search/project",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
dataType: "json",
success: function (message) {
console.log(message)
},
error: function (message) {
console.log("提交数据失败!");
}
});
//第二种方式(简洁的)
$.post("http://172.16.7.156:8080/cswadi-search/search/project",{
"fd_project_name": "",
"fd_total_size": "",
"ip_phase": ""
},
function(message){
console.log(message)
});
//发jsonp另一种方法
$.ajax({
url: url + "sdlOrgCoreIndex/list?orgId=0",
data: {},
"async": true,//这里开始
"crossDomain": true,
"headers": {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
"cache-control": "no-cache"
},
xhrFields:{
withCredentials:true
}, //这里结束(主要是添加这几行)
success: function (res) {
getMianDataDid(res)
},
});
//较为完整的发送
$.ajax({
url:"test.json",
type: "GET",
data: {username:$("#username").val()},
dataType: "json",
beforSend:function(){
// 禁用按钮防止重复提交
$("#submit").attr({ disabled: "disabled" });
},
complete:function(msg){
//请求完成后调用的回调函数(请求成功或失败时均调用)
} ,
error:function(msg){
//请求失败时被调用的函数
} ,
Sucess:function(msg){
//请求成功后调用的回调函数
}
});