X
X
xnkka2019-11-14 16:44:07
AJAX
xnkka, 2019-11-14 16:44:07

Why does the server return net::ERR_CONNECTION_CLOSED on ajax request?

On localhost, everything works fine, this problem got out on the server. Laravel/vue project. Ajax request code:

var firstHalf =  this.menu.slice(0, 21);
                var secondHalf =  this.menu.slice(21);
                var result = [firstHalf,secondHalf];
                this.isLoading = true;
                for (let i = 0; i < result.length; i++) {
                    let statusCode = 200;
                    axios({
                        method: "post",
                        url: "/admin/menu/addMenu/",
                        header: {
                            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                        },
                        params: {
                            menu: result[i],
                            startDate: this.selectedDate,
                            order: i + 1
                        }
                    }).then(response => {
                        console.log("ajax")
                        console.log(response.status);
                        console.log(response);
                        if (i+1>= result.length) {
                            this.message = response.data.message;
                            this.modalShow = true;
                            this.isLoading = false;
                            return;
                        }
                    });
                }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2019-11-14
@ThunderCat

Usually this means that the server does not give a response at all, or, well, it interrupts the connection due to broken headers, respectively, first of all we try to turn off everything except the request itself, then check if there is one at all and whether the corresponding route is responding ... well, check if there is anything at all then in

"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question