Can an ajax request be made to this url?

0

I would like to know if I can make an ajax request to this web page to download videos from youtube, I do not get it, in theory this would be enough to download the file no?

$(()=>{

  const api = 'http://youtubedl.xyz/download'
  const request = new XMLHttpRequest()
  request.open('POST', api, true)

  request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  request.send('url=https://www.youtube.com/watch?v=O09KF_abpdE')


});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    
asked by Carlos Arroyo 17.08.2018 в 18:28
source

1 answer

0

You can make ajax to remote domains, only if they have the header Access-Control-Allow-Origin that supports your domain or a wildcard as Access-Control-Allow-Origin: * . Or with browsers prior to these . Because it is a restriction made by browsers. If the server does not have this header, or you can ask to add it or you will have to download the videos from a server-side code. All this is because the browsers follow the Policy of the same origin . There is no other way with the most used browsers.

    
answered by 17.08.2018 в 18:56