1、$.ajax方法
方法描述:執行一個異步的HTTP的請求。
需求描述:執行一個異步的HTTP GET請求,從服務器加載數據。
$.ajax({
url: '/user/login',
type: 'get',
data: {
username: 'zhangsan',
password: '123456'
},
dataType: 'text',
success: function (response) {
alert(response);
},
error: function (response) {
alert(response);
}
});
需求描述:執行一個異步的HTTP POST請求,從服務器加載數據。
$.ajax({
url: '/user/login',
type: 'post',
data: {
username: 'zhangsan',
password: '123456'
},
dataType: 'text',
success: function (response) {
alert(response);
},
error: function (response) {
alert(response);
}
});
2.3.2、$.get方法
方法描述:使用一個HTTP GET請求從服務器加載數據。
這是一個ajax功能的縮寫,這相當於:
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
$.get('/user/login', {username: 'zhangsan', password: '123456'}, function (response) {
alert(response);
});
3、$.post方法
方法描述:使用一個HTTP POST請求從服務器加載數據。
這是一個ajax功能的縮寫,這相當於:
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
$.post('/user/login', {username: 'zhangsan', password: '123456'}, function (response) {
alert(response);
});