简体   繁体   中英

AJAX Access-Control-Allow-Origin

I am getting the error when trying to run m3u8 video :: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost ' is therefore not allowed access.

<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8 />
    <title>Video</title>

    <link href="http://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet">
    <script src="http://vjs.zencdn.net/4.12/video.js"></script>
    <script src="https://github.com/videojs/videojs-contrib-media-sources/releases/download/v0.1.0/videojs-media-sources.js"></script>
    <script src="https://github.com/videojs/videojs-contrib-hls/releases/download/v0.11.2/videojs.hls.min.js"></script>

</head>
<body>
<h1>Video</h1>

<video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="268"
       data-setup='{}'>

    <source src="http://my~server.com/recordings/91/2015-12-15/91_1450161600/91_1450161600.m3u8" type='application/x-mpegURL'>


</video>

<script>
    var player = videojs('my_video_1');
</script>

</body>
</html>

On http://my~server.com/ I have added .htaccess but it didn't work.

<IfModule mod_rewrite.c>

   RewriteEngine on
   <IfModule mod_headers.c>
                Header add Access-Control-Allow-Origin "*"
        Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
        Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
   </IfModule>

</IfModule>

Is there any PHP handling the request of your video? You can control the actual headers sent before the "video stream" starts.

I'm not sure that the .htaccess you have right there will cover the subfolders you are referring to as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM