S
S
Sedbol2020-08-04 21:37:47
CORS
Sedbol, 2020-08-04 21:37:47

What needs to be fixed so that the cross domain error does not appear?

Script for getting the date of registration in a contact

function dataReg(e){
                let r = new XMLHttpRequest();
                r.open('GET', 'https://vk.com/foaf.php?id=' + e, true);
                r.addEventListener("readystatechange", () => {
                    if (r.readyState === 4 && r.status === 200) {
                        var xd = (r.responseText.match(/ya:created dc:date="(.+)T(.+)"/i)||[]), ad, div;
                        if (xd) {
                            ad = xd[1].split('-');
                            div = document.createElement ('div');
                            div.className = 'clear_fix profile_info_row';
                            console.info(ad)
                        }
                    }
                });
                r.send()
            }
            dataReg(1);

Everything works fine from the browser console. I'm trying to run from an iframe application, I get an error
Access to XMLHttpRequest at 'https://vk.com/foaf.php?id=50781636' from origin 'https://vk-get.ru' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


How can you deal with this trouble?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2020-08-04
@inoise

Years passed, people never learned how to copy the text of the error in Google.
This is CORS. This cannot be bypassed on the client. Only if you set your "proxy" server

O
OCTAGRAM, 2020-10-29
@OCTAGRAM

VKontakte did not give such permission, that's all.
Hypothetically, you can get permission from VKontakte by registering as a developer, creating a new application, obtaining an API key and specifying the domain from which requests will come from the browser. Almost at some stage, you may still need your own server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question