C
C
Crash2018-04-25 16:29:48
JavaScript
Crash, 2018-04-25 16:29:48

Why am I getting 401 errors when making a fetch request?

I'm starting to learn Vue JS, as well as modern JavaScript features.
Client code:

var app = new Vue({
        el: '#ex-ways',
        data: {
            giveBanks: [],
            receiveBanks: [],
        },
        created: function() {
            this.getGiveBanks()
        },
        methods: {
            getGiveBanks: function(){
                var self = this;
                fetch('/front/get_give_banks', {
                    method: 'get',
                    headers: {
                        'Content-Type': 'application/json',
                    }
                }).then(function(response){
                    if (response.status == 200) {
                        console.log('success');
                    } else {
                        console.log(response);
                    }
                });
            }
        }
    });

Server code:
public function get_give_banks()
    {
        $banks = $this->db->where('give_money', 1)->get('banks')->result_array();
        echo json_encode($banks, JSON_UNESCAPED_UNICODE);
    }

I get 401 error - request not authorized. Why so, how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2018-04-25
@kulakoff Vue.js

I think that this problem does not concern vue, looking at the server side.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question