Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SoundCloud API给出了;未捕获的SyntaxError:意外标记:“0”;错误_Javascript_Jquery_Html_Jsonp_Soundcloud - Fatal编程技术网

Javascript SoundCloud API给出了;未捕获的SyntaxError:意外标记:“0”;错误

Javascript SoundCloud API给出了;未捕获的SyntaxError:意外标记:“0”;错误,javascript,jquery,html,jsonp,soundcloud,Javascript,Jquery,Html,Jsonp,Soundcloud,在控制台中,它给了我一个错误“uncaughtsyntaxerror:Unexpected token:”,但如果我在浏览器中访问DirectSoundCloud URL,那么它给的是有效的JSON。早些时候,这段代码运行良好,今天这个问题就开始了 <html> <head> <script src="https://api.soundcloud.com/resolve.json?url=https://api.soundcloud.com/trac

在控制台中,它给了我一个错误“uncaughtsyntaxerror:Unexpected token:”,但如果我在浏览器中访问DirectSoundCloud URL,那么它给的是有效的JSON。早些时候,这段代码运行良好,今天这个问题就开始了

<html>
    <head>
    <script src="https://api.soundcloud.com/resolve.json?url=https://api.soundcloud.com/tracks/251912676/?secret_token=s-EkyTy&amp;client_id=08f79801a998c381762ec5b15e4914d5"></script>
    </head>
    <body>
    <h2>hellooo</h2>
    </body>
</html>

下面的脚本标记要求源代码中包含JavaScript代码,而不是JSON

<script src="file.js"></script> 

我想您应该使用这个外部生成的json

“获取”它的一种方法是使用异步ajax请求,如
$.get(url,回调)

将其作为脚本调用肯定会失败…
因为这不是剧本

尝试运行代码段

var url=”https://api.soundcloud.com/resolve.json?url=https://api.soundcloud.com/tracks/251912676/?secret_token=s-EkyTy和客户id=08f79801a998c381762ec5b15e4914d5“
var-json;
$.get(url、函数(结果){
json=结果;
//在控制台中显示
log(JSON.stringify(JSON));
//现在使用它。。。
$(“#json_用法”).html(json.tag_list+”和所有“+json.permalink”);
});

你好!

我知道了问题的原因,之前soundcloud在jsonp中响应,但现在他们提供JSON,即使我传递了jsonp回调函数。我不得不提出ajax请求来修复它

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
           callback( JSON.parse(this.responseText) );
        }
    };
    xhttp.open("GET", url, true);
    xhttp.send();
我使用以下代码来修复它

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
           callback( JSON.parse(this.responseText) );
        }
    };
    xhttp.open("GET", url, true);
    xhttp.send();

很抱歉,您在SoundCloudAPI的JSONP响应方面遇到了问题。这是因为在过去几天里有一个bug进入了生产。我们刚刚部署了一个修复程序,因此如果您指定
回调
参数,该端点现在将返回有效的JSONP响应,而不仅仅是JSON响应。抱歉搞混了

为什么要将JSON文件作为脚本导入?JSON不是JavaScript。你的意思是使用JSONP吗?实际上这是代码的一部分,我们有一个定制的音频播放器,使用react for soundcloud,我们得到了JSONP响应,一切都很好,但从今天开始就出现了错误。为什么有人在这里给了负分,我可能没有很好地描述,但问题是什么,我的代码中有回调函数。我们遇到了同样的问题,我想他们的API中一定发生了一些变化……你是如何解决的?我从昨天开始就有相同的问题。我有相同的问题,请提供您的解决方案。谢谢对不起,我的无知,但这代码到哪里去了?我们只是将sc player类用于自定义小部件。此代码是否包含在sc-player.js中?而且似乎只有70%的音轨受到影响——有些音轨播放得很好。为什么会这样?