I'm trying to integrate FedEx API in the web applications but I'm getting cors error. Here is my console error output, enter image description here
Can anyone please help to how to resolve this cors error in FedEx API integration?
Here is my code,
$.ajax({
type: "POST",
url: "https://wsbeta.fedex.com:443/web-services",
data: xmlData,
contentType: "text/xml",
dataType: "xml",
cache: false,
cors: true,
success: function(result) {
console.log('success');
console.log('result ', result);
},
error: function() {
console.log('Failed to Validate Shipment Request');
}
});
CodePudding user response:
Add headers in your ajax request
headers: { 'Access-Control-Allow-Origin': '*', },
CodePudding user response:
Cross-origin resource sharing is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served.
Please try to install cors package
npm i cors
Configuring CORS set as Middleware
var express = require('express')
var cors = require('cors') var app = express()
var corsOptions = { origin: 'http://example.com', optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 }