xtrime-ru / TelegramApiServer

Fast, simple, async php telegram api server: MadelineProto + Amp HTTP Server
https://tg.i-c-a.su
MIT License
529 stars 116 forks source link

CORS Policy Error: Blocked XMLHttpRequest #124

Closed IhsanDevs closed 1 year ago

IhsanDevs commented 1 year ago

Code in my download.blade.php :

<script>
document.getElementById('downloadButton').addEventListener('click', async () => {
  const backendUrl = '{{ env('BACKEND_URL') }}';
  const url = backendUrl + '/api/getDownloadInfo';
  @php
      $media = json_encode([
        'media' => $media
      ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  @endphp
  const requestData = JSON.stringify({!! $media !!})
  console.log(requestData);
  var settings = {
    "url": url,
    "method": "POST",
    "timeout": 0,
    "headers": {
        "Content-Type": "application/json",
        "Access-Control-Allow-Origin": "*",
    },
    "data": requestData,
};

    // download an async file from the URL with raw data requestData using the POST method. use jQuery
    $.ajax(settings).done(function (response) {
        console.log(response);
    });

});
</script>

But getting an error in my browser console:

Access to XMLHttpRequest at 'http://127.0.0.1:8003/api/getDownloadInfo' from origin 'http://localhost:8000' 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.