0

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');
    }
});
Sadashiv M
  • 11
  • 2
  • `$.ajax({ ..., crossDomain: true, ... })` – Ergis Nov 03 '21 at 13:15
  • Does this answer your question? [How to get a cross-origin resource sharing (CORS) post request working](https://stackoverflow.com/questions/5750696/how-to-get-a-cross-origin-resource-sharing-cors-post-request-working) – Ergis Nov 04 '21 at 08:18

2 Answers2

0

Add headers in your ajax request

headers: { 'Access-Control-Allow-Origin': '*', },

-1

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 with this command:

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
 }
JW Geertsma
  • 857
  • 3
  • 13
  • 19
  • He didn't mention that he's using NodeJS. It's just an ajax call, so don't scope down the answer to NodeJS ! – Ergis Nov 03 '21 at 13:15