Web 各類數據請求

一 jQuery AJAX

$.ajax({
    type: "POST",
    url: '/someUrl',
    data: {"id":id},
    dataType:'json',
    cache: false,
    success: function(data){
        $.each(data.list, function(i, list){
            nextPage(${page.currentPage});
        });
    }
});

二 Vue axios

axios.get('/someUrl')
.then(function (response) {
  console.log(response);
})
.catch(function (error) {
  console.log(error);
});

axios({
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/someUrl',
    data: {},
    transformRequest: [function (data) {
    }]
}).then(function (response) {
});

三 Angular1.5.5

3.1 get請求(通用方法)

$http({
    method: 'GET',
    url: '/someUrl'
}).success(function (response) {
    // this callback will be called asynchronously
    // when the response is available
}).error(function (response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

3.2 get請求(簡寫方法)

$http.get('/someUrl', config).success(function (response) {
    // this callback will be called asynchronously
    // when the response is available
}).error(function (response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

 
四 Angular1.6.3

4.1 get請求(通用方法)

$http({
    method: 'GET',
    url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
}, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

4.2 get請求(簡寫方法)

$http.get('/someUrl').then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
}, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章