jQuery写请求方法
- GET方法
function getAjax() {
$.ajax({
type: GET,
url: https://music.benwebsite.cloud/banner,
data: {
type: 2
},
dataType: JSON,
async: true,
success: function(data) {
if(data.code == 200) {
console.log('成功');
console.log(data);
}else{
console.log('错误');
}
}
error: function() {
}
})
}
- POST方法
function postAjax() {
$.ajax({
type: 'POST',
url: 'https://music.benwebsite.cloud/banner',
data: {
type: 2
},
dataType: JSON,
async: true,
success: function(data) {
if(data.code == 200) {
console.log('成功');
console.log(data);
}else{
console.log('错误');
}
}
error: function() {
}
})
}
- PUT方法
function petAjax() {
$.ajax({
type: 'PUT',
url: 'https://music.benwebsite.cloud/banner',
data: {
type: 2
},
dataType: JSON,
async: true,
success: function(data) {
if(data.code == 200) {
console.log('成功');
console.log(data);
}else{
console.log('错误');
}
}
error: function() {
}
})
}
- DELETE方法
function deleteAjax() {
$.ajax({
type: 'DELETE',
url: 'https://music.benwebsite.cloud/banner',
data: {
type: 2
},
dataType: JSON,
async: true,
success: function(data) {
if(data.code == 200) {
console.log('成功');
console.log(data);
}else{
console.log('错误');
}
}
error: function() {
}
})
}