This is my first question here and I'm totally stumped. Basically, I have a cart page that looks like this:
The site works by customers uploading images for printing, so each order is actually an image. Each cart item is generated dynamically using JS DOM functions, but the part I'm having trouble with is the row below the "Item #1" header row. It's supposed to contain a thumbnail of the order image (uploaded by the customer), which I get from a Laravel API endpoint. It returns a base64 string of the image, which I set as the image source like this:
var tbody = document.createElement('tbody');
var productImageRow = document.createElement('tr');
var productImageTD = document.createElement('td');
var productImage = document.createElement('img');
productImageTD.colSpan = 2;
if (order.productType == PRODUCT_TYPES.CONDUCTION_PLATES) {
/* Some irrelevant code here... */
} else {
$.get(<API Endpoint here>, function(data) {
productImage.src = data;
});
}
productImageTD.appendChild(productImage);
productImageRow.appendChild(productImageTD);
tbody.appendChild(productImageRow);
The problem is, even if I change the image src, it's not reflected in the browser (hence the empty row below the table header).
I am sure that the API is working because I do this exact same thing in another page and it works fine. Aside from that, if I log the base64 string in the data variable to the console and directly place it in the html like
<img src="<my base64 string>">
it displays the image fine, so I'm sure the base64 string is valid.
I also know that the success block is being executed because alerts inside it execute. When tested further, any DOM Manipulation done inside the callback doesn't get reflected in the browser. Example:
var DOMTest = document.createElement('h1');
DOMTest.innerHTML = "Before Callback";
productImageTD.appendChild(DOMTest);
...
$.get(<API Endpoint here>, function(data) {
//productImage.src = data;
DOMTest.innerHTML = "After Callback"
alert(DOMTest.innerHTML);
});
The result is that the page still displays the h1 as "Before Callback", but the alert shows the innerHTML as "After Callback". I tested this on Safari and Chrome.
I'm pretty sure I might just be making some stupid mistake. Any ideas? I'm totally lost here.