Making a test environment for some Google Cloud functions. I have the following code:
function submitRequest()
{
url = <function url>;
return Get(url,false);
}
async function Get(url) {
const otherArgs = {
method: 'GET',
Authorization: "Bearer" + idToken.i
};
let response = await fetch(url, otherArgs);
if(response.ok) {
console.log("Get request to " + url + " succeeded with code " + response.status);
return await response.text();
} else {
console.log("Get request to " + url + " failed with code " + response.status);
return undefined;
}
}
Then in my index file I have:
document.getElementById("submitRequestBtn").addEventListener("click", function() {
response = submitRequest();
document.getElementById("mainP").innerHTML = response.text;
});
The function succeeds and that shows up in the console, but it simply prints "undefined" in the HTML paragraph tag that should hold a json string. I thought the awaits in my Get function would cause the other functions to wait before returning, but they are not. "Undefined" shows up before I get the console message that the request succeeded. How can I get my submitRequest function to return the actual content of the response instead of undefined?