I just want to start out by saying I’m a javascript newbie – this is for an addon to a .NET project I’m working on. Also I’ve read through a dozen related questions – most of them relate to the poster trying to access the fetch response outside of the asynchronous handler, which I’m not.
This is pretty barebones – I’m asking the javascript to request a string from the server given some variables (here order and hidelots). I’ve confirmed server-side that it’s sending the correct requested data. Since I’m new to js, I’m trying to confirm in the javascript that it’s receiving the data. I’m using this line:
let promise = fetch(window.location.origin + '/OrderData/?order=' + params.get(""order"") + '&hidelots=' + (this.checked ? 1 : 0))
.then(response => window.alert('Returning: ' + response.text()));
The goal is to just give an alert with the text returned a the time it’s returned. The popup says “Returning: [object Promise]”. It does wait until the server responds – I’ve delayed the server to test that. But I can’t figure out how to access the string.
For the sake of completeness – response.status returns “200”, response.statusText returns “OK” and response.url returns “http://192.168.1.180:1932/OrderData/?order=385&hidelots=1”. The expected text() is the innerhtml of a table body – “lorem ipsum”
How do I access the string?