본문 바로가기
Develop/Javascript

[jQuery] ajax 클로저 방식

by bellsilver7 2019. 4. 15.
728x90
let ajaxController = {
    init: function() {
        this.type = "post";
        this.url = "";
        this.data = "";
        this.dataType = "json";
    },
    start: function() {
        let result = null;
        $.ajax({
            async: false,
            url: this.url,
            type: this.type,
            data: this.data,
            dataType: this.dataType,
            success: function (json) {
                if (json.status !== 200) {
                    alert(json.message);
                    console.log(json);
                    return false;
                }
                result = json;
            },
            error: function (xhr, status, errorThrown) {
                console.log("1." + errorThrown + "\n2." + status + "\n3." + xhr.statusText + '\n4.' + xhr.status);
            }
        });
        return result;
    }
};


ajaxController.init();
ajaxController.url = "/api/get_order_list.php";
ajaxController.data = formData;
let json = ajaxController.start();
728x90

댓글