2016-08-02 12 views
1

Ich habe einen CORS-Fehler, wenn ich versuche, Video von einer anderen Domäne herunterzuladen. Ich habe viel versucht, um es zu lösen, konnte aber nicht. Unten ist mein Js-Code.vor einem CORS-Fehler

getVideoFile = function() { 
 
\t \t \t var xhr = new XMLHttpRequest(), 
 
\t \t \t blob; 
 
\t \t \t xhr.open("GET",myVideo, true); 
 
\t \t \t xhr.responseType = "blob"; 
 
\t \t \t xhr.addEventListener("load", function() { 
 
\t \t \t if (xhr.status === 200) { 
 
\t \t \t \t blob = xhr.response; 
 
\t \t \t \t putVideoInDb(blob); 
 
\t \t \t \t window.alert("Video file downloaded"); 
 
\t \t \t } 
 
\t \t \t else { 
 
\t \t \t \t window.alert("Unable to download video"); 
 
\t \t \t } 
 
\t \t \t }, false); 
 
\t \t \t xhr.send(); 
 
\t \t }; 
 

 
\t \t putVideoInDb = function (blob) { 
 
\t \t \t var transaction = db.transaction(["Videos"], "readwrite"); 
 
\t \t \t var store = transaction.objectStore("Videos"); 
 
\t \t \t var vid = { 
 
\t \t \t \t \t videoName:videoName, 
 
\t \t \t \t \t video:blob, 
 
\t \t \t \t } 
 
\t \t \t var request = store.add(vid); 
 
\t \t \t request.onerror = function(e) { 
 
\t \t \t \t \t console.log("Error",e.target.error.name); 
 
\t \t \t \t } 
 
\t \t \t request.onsuccess = function(e) { 
 
\t \t \t \t \t console.log("Done!!"); 
 
\t \t \t \t } 
 
\t \t };

Antwort

0

Werfen Sie einen Blick auf diese Frage: CORS error on same domain?

Natürlich ist dies ein Szenario, in dem die Domäne ist die gleiche, aber aber die Logik ist die gleiche ...

Es gibt viele Artikel zu diesem Thema.

+0

Ich möchte es nur mit Javascript und nicht AJAX jquery tun. Es wäre sehr hilfreich, wenn Sie die Lösung mit Javascript bereitstellen könnten. – Nikhil