简体   繁体   中英

jQuery ajaxs CORS request

I am calling jQuery ajax request, at CORS resourse. Backend works on nginx, and there set OPTIONS hook and response with allowed all domains, and all request types. But unfortunatly i am getting error calback. On Chrome Network console i saw 204 answer on OPTIONS request. And I have never seen my original POST request.

var email = $('#your_email').val();
var sendData = {
    issue: {
        description: "email:" + email,
        category_id: 1
    }
};

$.ajax({
    url: "https://domen/issues.json",
    type: "POST",
    beforeSend: function (xhr) {
        xhr.setRequestHeader("Authorization", "Basic " + btoa("goodtry:goodtryq"));
        xhr.setRequestHeader("Accept", "application/json");
        xhr.setRequestHeader("Content-type", "application/json")
    },
    data: JSON.stringify(sendData),

    success: function (val) {
        alert("Thanks you, we are going to contact you soon");
    },
    error: function (val) {
        alert("Please check your internet connection");
    }
});

在此处输入图片说明

在此处输入图片说明

So it is solved. I missed diagnostic message

Request header field Authorization is not allowed by Access-Control-Allow-Headers.

So helpful answer culd be found here: https://stackoverflow.com/a/24556330/2835239

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM