Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross domain at axios

I am changing jquery ajax for axios and I not getting use axios with cross domain:

axios.get(myurl, {
            headers: { 'crossDomain': true },
        }).then(res => { 
            console.log(res);

        }).catch(error => {
            console.log('erro', error);
        })

My jquery code is working:

$.ajax({
   type: 'GET',
   crossDomain: true,
   url:myurl,
   success: (res) => {},
   error: (fail) => {}     
})

The error: Request header field crossDomain is not allowed by Access-Control-Allow-Headers in preflight response.

Can anyone help me?

like image 748
Alessander França Avatar asked Feb 23 '17 17:02

Alessander França


People also ask

Has been blocked by CORS policy no access control allow origin in Axios?

[Solved] Axios request has been blocked by cors no 'Access-Control-Allow-Origin' header is present on the requested resource. Solution 1: Access-Control-Allow-Origin is a response header - so in order to enable CORS - We need to add this header to the response from server.

What is crossDomain true?

crossDomain (default: false for same-domain requests, true for cross-domain requests) Type: Boolean If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain. ( version added: 1.5)


Video Answer


1 Answers

"crossDomain" does not have to be in headers

axios.get(myurl, {
    crossDomain: true
}).then(res => { 
    console.log(res);
}).catch(error => {
    console.log('error', error);
})

Regards

like image 153
Billy Tsk Ctr Avatar answered Sep 20 '22 12:09

Billy Tsk Ctr