shawn
February 1, 2019, 8:21pm
1
I’m trying to do an XMLHttpRequest to access a json from a URL.
I looked at the sample doc:
const { ImageFill } = require("scenegraph");
const uxp = require("uxp").storage;
const fs = uxp.localFileSystem;
function applyImage(selection) {
if (selection.items.length) {
const url = "https://dog.ceo/api/breeds/image/random";
return fetch(url)
.then(function (response) {
return response.json();
})
.then(function (jsonResponse) {
return downloadImage(selection, jsonResponse);
});
} else {
console.log("Please select a shape to apply the downloaded image.");
}
}
async function downloadImage(selection, jsonResponse) {
This file has been truncated. show original
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?
Did you try full example on this or just a code snipet if not try full example by copy paste
const { ImageFill } = require("scenegraph");
const uxp = require("uxp").storage;
const fs = uxp.localFileSystem;
function applyImage(selection) {
if (selection.items.length) {
const url = "https://dog.ceo/api/breeds/image/random";
return fetch(url)
.then(function (response) {
return response.json();
})
.then(function (jsonResponse) {
return downloadImage(selection, jsonResponse);
});
} else {
console.log("Please select a shape to apply the downloaded image.");
}
}
async function downloadImage(selection, jsonResponse) {
This file has been truncated. show original
even when you get error where your code is failing
post log or something so others can better understood
return fetch(url)
.then(function (response) {
return response.json();
})
.then(function (jsonResponse) {
return downloadImage(selection, jsonResponse);
});
is this not sufficient for your requirement ?
1 Like
The URI scheme is the problem – XD only permits https
requests.
1 Like
shawn
February 4, 2019, 8:16pm
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.
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!