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?
[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.
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)
"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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With