G
G
grigorie19902019-12-09 16:33:41
JavaScript
grigorie1990, 2019-12-09 16:33:41

Fetch request fails, CORS problem, how to solve?

Good afternoon!
I'm making a widget 37.46.128.6 posted on the test server, it requests my server. I have 'Access-Control-Allow-Origin': '*' on my nginx server, swears at 'Access-Control-Allow-Origin' in the console

fetch('https://bc4e9c9a.ngrok.io/widget/generate', {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            terminal_id: dataTerminalId,
            amount: dataAmount,
            organization_id: dataOrganizationId,
            user_id: dataUserId
        })
    }).then((response) => {
        response.json().then(function (json) {
            if (json) {
                qr.setAttribute("src", json.qr);
                iframe.setAttribute("src", json.iframeSrc);
                iframe.setAttribute('frameBorder', '0');
                url = json.iframeSrc;
                operationId = json.operationId;
            }
        });
    });

set mode cors and the title added 'Access-Control-Allow-Origin': '*' there is no effect
, while the code above for loading the html file works
request.open('get', 'https://bc4e9c9a.ngrok.io/widget_evolpay.html', true);
    // request.setRequestHeader('Access-Control-Allow-Origin', 'http://37.46.128.6/');

    request.onload = function () {
        if (request.status >= 200 && request.status < 400) {
            console.log(1);
            let resp = request.responseText;
            document.querySelector('#widget-evolpay').innerHTML = resp;
            r();
        }
    };
    request.send();

bc4e9c9a this is my server this is ngrok tunnel to my computer

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nikita Kravchenko, 2019-12-09
@nkdev55

Forward the request through your server.
You send a POST request to your server and from there you send a POST to bc4e9c9a.

K
kirillleogky, 2019-12-09
@kirillleogky

grigorie1990 https://youtu.be/DYR8g_kI9Xs?t=2458
everything is detailed there

B
Boris Cherepanov, 2019-12-09
@xakplant

https is not here and swears.
Try https://www.npmjs.com/package/fetch-json

X
xmoonlight, 2019-12-09
@xmoonlight

Content-type: plain/text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question