JQuery ajax request is block because Cross-Origin

How to get content from a remote URL via AJAX?

jQuery AJAX request is blocked because Cross-Origin

Console magazine

Cross-request blocking: the same origin policy prohibits reading a remote resource at http://www.dailymotion.com/embed/video/x28j5hv . (Reason: CORS header "Access-Control-Allow-Origin" is missing.)

Cross-request blocking: the same origin policy prohibits reading a remote resource at http://www.dailymotion.com/embed/video/x28j5hv . (Reason: CORS request failed).

The code

$.ajax({
url: "http://www.dailymotion.com/embed/video/x28j5hv",
type:'GET',
contentType: "html",
crossDomain:true,
success: function(data){
   //$('#content').html($(data).html());
   var src = $(data).html();
    alert(src);
    return false;
}
+7
source share
3 answers

JSONP Ajax. .

http://learn.jquery.com/ajax/working-with-jsonp/

$.ajax({
    url: "https://api.dailymotion.com/video/x28j5hv?fields=title",

    dataType: "jsonp",
    success: function( response ) {
        console.log( response ); // server response
    }

});
+13

( ). crossDomain , (dailymotion.com) COORS.

, , - script , . - ? PHP, Python, ASP.NET ..? , "" script, HTTP- dailymotion . script Javascript-, script , script, COORS .

+3

Try using a cURL request for a cross-domain.

If you work through third-party APIs or receive data through CROSS-DOMAIN, it is always recommended to use the cURL script (server-side), which is more secure.

I always prefer the cURL script.

0
source

Source: https://habr.com/ru/post/1598672/


All Articles