Whenever I try to run this function:
async function jget(url){
await $.get(url, html => {
return html
})
}
I get an error like this:
(node:13924) UnhandledPromiseRejectionWarning: #<Object>
How can I fix this?
Whenever I try to run this function:
async function jget(url){
await $.get(url, html => {
return html
})
}
I get an error like this:
(node:13924) UnhandledPromiseRejectionWarning: #<Object>
How can I fix this?
You should put the "$.get(url, handlerFunction)" into a promise as await expects a Promise to return, so instead of your code you can write your code like below.
async function jget(url){
// Note: Below variable will hold the value of the resolved promise
let response = await fetchingData(url);
}
function fetchingData(url) {
return new Promise((resolve, reject) => {
$.get(url, html => {
resolve(html)
})
})
}