Async Function Must Return A Boolean Value
I have a method that I am calling on the onsubmit event in the form tag. So I need a true or false to be returned from the method. I use an API to retrieve data, and according to t
Solution 1:
GetPolygonID()
function returns a Promise, so it must be either called with await
or you can call then
upon it:
var res = awaitGetPolygonID();
GetPolygonID().then(res =>console.log(res));
You can make the whole function async
:
asyncfunctionGetPolygonID() {
document.getElementById("displayerror").innerHTML = "";
var retrievedpoly = document.getElementById('polygondetails').value;
var parts = retrievedpoly.split('coordinates');
var parttoadd = parts[1].substring(0, parts[1].length - 2) + "}";
console.log(parttoadd);
var myx = '{"name":"Polygon OneTwoThree","geo_json":{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates' + parttoadd;
var url = 'http://api.agromonitoring.com/agro/1.0/polygons?appid=apiid';
const response = awaitfetchPoly(url, myx);
const data = response.json();
const errorCheck = CheckInfo(data);
console.log("2: " + errorCheck);
return errorCheck;
}
Using an async
function for a form validation, you can do this:
functiononSubmit(form) {
GetPolygonID().then(res => res ? form.submit() : null);
returnfalse;
}
...
<form method="POST" onsubmit="return onSubmit(this);">
...
Post a Comment for "Async Function Must Return A Boolean Value"