XMLHTTPRequest Error: Synchronous XMLHttpRequest on the main thread is deprecated … (SoundCloud API)

前端 未结 1 1692
不思量自难忘°
不思量自难忘° 2020-12-12 01:56

I\'m using an XMLHttpRequest to access SoundClouds Top Trending Tracks (https://api-v2.soundcloud.com/charts?kind=trending&genre=soundcloud:genres:all-m

相关标签:
1条回答
  • 2020-12-12 02:31

    You are using XMLHttpRequest wrong. Do asynchronous request instead of synchronous. Here is a fixed version:

    function initialSearch() {
        var xhr = new XMLHttpRequest();
        xhr.addEventListener("load", function() {
            initialArray = JSON.parse(xhr.response);
        }, false);
        xhr.open('GET', "https://api-v2.soundcloud.com/charts?kind=trending&genre=soundcloud:genres:all-music&client_id=1dff55bf515582dc759594dac5ba46e9&q=");
        xhr.send();
    }
    

    But even then, you will get No 'Access-Control-Allow-Origin' header is present on the requested resource error. Which is CORS browser policy error. You can only make requests to the same origin resources.

    So if you can modify your server code, do that request from your server and change your client AJAX request to ask data from your server.

    0 讨论(0)
提交回复
热议问题