How to read JSON with XMLHttpRequest


#1

I’m trying to do an XMLHttpRequest to access a json from a URL.
I looked at the sample doc:

Didn’t get much out of it though… Here is my code:

    const Http = new XMLHttpRequest();
    const url ='http://feeds.nfl.com/feeds-rs/roster/2510.json';
    Http.open("GET", url);
    Http.send();
    Http.onreadystatechange=(e)=>{
        console.log(Http.responseType);
    }

Can anyone point me to a simple sample request or help me correct my code?


#2

Did you try full example on this or just a code snipet if not try full example by copy paste

even when you get error where your code is failing

post log or something so others can better understood


#3
return fetch(url)
            .then(function (response) {
                return response.json();
            })
            .then(function (jsonResponse) {
                return downloadImage(selection, jsonResponse);
            });

is this not sufficient for your requirement ?


#4

The URI scheme is the problem – XD only permits https requests.


#5

@kerrishotts - Thank you. I’m finding a lot of restrictions for coding in XD so far. The url I gave as an example above is a very specific sample of data that I use daily at work. It’s a shame that I can’t access it for prototyping.


#6

I think it’ll work on Windows – the restriction here is because of Apple’s ATS, which XD enables by default.

You might be able to have a local proxy running that takes care of the security? Not sure. Would love to know more about your use case here – DM me if you want!