0

I'm making a Java Compiler website for myself and I'm using JDoodle
In the document of this API, shows NodeJS code execute function (https://docs.jdoodle.com/integrating-compiler-ide-to-your-application/compiler-api)
and I'm using javascript in html so I change a little bit to

// using jQuery
$.ajax({
        url,
        type: 'post',
        data,
        headers: {
            'Content-Type': 'application/json'
        },
        dataType: 'json',
        success: function(data) {
            console.log(data);
        }
    })

but it gave me this error

Access to XMLHttpRequest at 'https://stage.jdoodle.com/execute' from origin has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I also tried $.post and Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not? but still the same.
Thank you!!

1 Answers1

0

You need to enable header on the server side.

This has been asked before Enable CORS in fetch api

Alternatively you can ignore CORS with a flag.

NotoriousPyro
  • 526
  • 3
  • 16