Need some coding help!
GOAL: Display images(url) pulled from DB
CURRENTLY:
I can get the image(url) from DB.
I can get image(url) to display(mobile) correctly if I manually insert the image(url).
** I can’t seem to figure out how to combine the 2 functions.
CODE 1: Load Image(url)
How would I insert image(url) from Z.jax?
const Image_PlanePico = symbol.nodes.Image_PlanePico;
var image1 = Z.ImageTexture(“Image(url) from API”).wrap(Z.Texture.Wrap.clamp);
parent.on(“pointerdown”, (e) => {
// Runs when pointerdown occurs on the parent node
// The argument e contains useful info about this event:
// https://docs.zap.works/studio/scripting/reference/object/events/pointerdown/
Image_PlanePico.skin (image1);
});
CODE 2: Get image(url) from DB
What code is needed get the data received from Z.jax to work with the CODE 1?
const Image_PlanePico = symbol.nodes.Image_PlanePico;
var imageData1;
// This will get the data from your DB field .image will display first one.
// Parameters to configure the AJAX request
const ajaxParameters : Z.Ajax.Parameters = {
url: “https://hook.integromat.com/amwlr9l4yfvuv44snlpuuxp9l1th5hhf”,
};
// Perform the AJAX request
Z.ajax(ajaxParameters, (statusCode, data, request) => {
if (statusCode === 0) {
Image_PlanePico.skin (“Unable to connect - check network connection.”);
return;
}
if (statusCode < 200 || statusCode >= 300) {
Image_PlanePico.skin ("HTTP request failed: " + statusCode);
return;
}
// Attempt to parse the data returned from the AJAX request as JSON
let imageData1;
try {
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
imageData1 = JSON.parse(data);
} catch (e) {
Image_PlanePico.skin("Unable to parse JSON: " + e);
return;
}
// Check the data is as expected and display it
if (imageData1.company) {
Image_PlanePico.skin(imageData1.image);
} else {
Image_PlanePico.skin (“Unexpected response from API”);
}
});
any thoughts? @stevesanerd or @George