0

Rewriting my original question since I was told its a duplicate which I feel it isn't.

I am new to jQuery AJAX. I have a ASP.NET WebForm that I'm trying to now connect to a generic handler. I'm trying to connect to a generic handler but I think I'm getting an error "Accessing the 'arguments' property of a function is not allowed in strict mode" as that's what it says when I hover over the $.ajax wile its in debug mode. The code is as follows. How do I get rid of Strict Mode? This happens in IE, FireFox and Chrome.

    <script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "/Common/Handlers/Default.ashx",
            cache: false,
            dataType: "xml",
            success: function (xml) {
                $(xml).find('entry').each(function () {
                    $(this).find("yt:videoId").first();
                    var name = $(this).text();
                    alert(name);
                });
            },
            error: function () {
                alert('Error loading XML document');
            }
        });
    });
</script>
CreationSL
  • 55
  • 1
  • 11
  • The code is not working. If you check the console you'l see that you are getting a CORS error. This is because you cannot make cross-domain requests without the third party domain expressly allowing it by returning specific headers in the request, or formatting the response in a specific manner. Neither of those are the case for Youtube. To achieve what you need you could proxy the request from your local server. See the duplicate I've marked for more details. – Rory McCrossan May 23 '19 at 19:51
  • From the updated description it seems you might want POST not GET here? add the jQuery version to your question - not sure it matters but just to be safe. – Mark Schultheiss May 23 '19 at 20:43

1 Answers1

0

Youtube offer a good V3 API that support native javascript JSON data structure. https://developers.google.com/youtube/v3/getting-started You need to get your API key before.

Example of usage:

var videosURL = "https://www.googleapis.com/youtube/v3/playlistItems?playlistId={myPlaylistID}&key={myAPIKey}&fields=items&part=snippet&maxResults=6&callback=?";

$.getJSON(videosURL, function(data) {
    $.each(data.items, function(i,val) {
        console.log(val.snippet.title);
        console.log(val.snippet.resourceId.videoId);   
    });
});