Same origin policy for jQuery vs Browser (with OData)

I am creating an AJAX application to query an OData endpoint. I tested the Netflix OData feed and found what I am not getting:

When I make a .ajax () request for a URL (e.g. http://odata.netflix.com/v1/Catalog/Titles ), I get an error: "Origin null is not allowed through Access-Control-Allow- Origin. " However, when I put the same url in my browser, the request goes through and I get a response.

What is the fundamental difference here that I am not getting? How does a browser bypass a policy of the same origin?

+3
source share
2 answers

JSONP Oflata Netflix. , . http://bit.ly/95HXLM

:

49.        // Make JSONP call to Netflix
50.     $.ajax({
51.            dataType: "jsonp",
52.            url: query,
53.            jsonpCallback: "callback",
54.            success: callback
55.            });
56.        });
57. 
58.    function callback(result) {
59.        // unwrap result
60.        var movies = result.d.results;
61. 
62.        $("#movieTemplateContainer").empty();
63.        $("#movieTemplate").tmpl(movies).appendTo("#movieTemplateContainer");
64.    }
+2

HTTP-, , . , , , , haxors.r.us, , HTTP- bankofamerica.com . , , HTTP- . , , . !

URL , ( - , ). Netflix API JSONP, GET script, Javascript.

, jQuery. XMLHttpRequest.

+1

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


All Articles