Skip to content
Advertisement

Getting a value from Javascript Async request and use it for further logic

I want to get a value from the async javascript call and store the retuned value in a variable and then write some logic based on the value.

My Javascript file looks like this.

JavaScript

Now in my HTML I would like to call the myBlur1 function and store the return value and then outside the function call I would like to build logic based on the return value.

Here is my HTML file.

JavaScript

I am always getting I am inside IIFE I am not yet ready. and after that the return arrays from async call.

Please help.

Advertisement

Answer

To get your result, you have to make the scope inside script tag compatible with step by step asynchronous operations. so put whole code inside script in async IIFE.

JavaScript

more simplified updated version(as we are already inside async function)

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement