JavaScript错误:在严格模式下不允许访问函数的'arguments'属性

时间:2019-05-23 19:25:23

标签: jquery asp.net xml

重写我的原始问题,因为有人告诉我它不是一个重复的问题。

我是jQuery AJAX的新手。我有一个ASP.NET WebForm,现在尝试连接到通用处理程序。我正在尝试连接到通用处理程序,但是我想收到一个错误“严格模式下不允许访问函数的'arguments'属性”,因为这就是我将鼠标悬停在$ .ajax wile上时的意思。它处于调试模式。代码如下。如何摆脱严格模式?在IE,FireFox和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>

1 个答案:

答案 0 :(得分:0)

Youtube提供了一个很好的V3 API,它支持本机javascript JSON数据结构。 https://developers.google.com/youtube/v3/getting-started 您需要先获取API密钥。

用法示例:

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);   
    });
});