PostIT

[AngularJS/JQuery] AngularJS에서 Ajax통신 시 JQuery와 문법 차이 본문

Script/Angular

[AngularJS/JQuery] AngularJS에서 Ajax통신 시 JQuery와 문법 차이

shun10114 2017. 3. 28. 11:16

# AngularJS와 JQuery Ajax 통신 시 문법 차이


1. Angular JS

$http({

    /* HTTP 통신 방법 */

    method : 'GET', 

    /* 통신 할 URL */

    url : root + "/news/list-json",

    timeout : 600000,

    /* 보낼 변수 */

    params : {

        "currentPage" : currentPage

    },

    /* 데이터 타입. */

    responseType : 'json',

    headers : {

        "Content-Type" : "application/json; charset=utf-8",

        "Accept" : "application/json",

        csrfHeader : csrfToken

    }

}).then(function(response) {

    console.log("Success");

}, function(error) {

    console.log("Error" + error);

});



2. Jquery


$.ajax({

    /* HTTP 통신 방법 */

    type : "GET",

    /* 통신 할 URL */

    url : root + "/survey/binding/bind/group",

    timeout : 600000,

    /* 보낼 변수 */

    data : {

        "surveyBindingGroupId" : surveyBindingGroupId

    },

    /* 데이터 타입. */

    dataType : "json",

    beforeSend: function(xhr) {

        xhr.setRequestHeader("Accept", "application/json");

        xhr.setRequestHeader("Content-Type", "application/json");

        xhr.setRequestHeader(csrfHeader, csrfToken);

    }, success : function(response) {

        console.log("Success");

    }, error : function(xhr, status, err){

        console.log('Error');

    }

});








Comments