asynchronous function to get data from server

0 Marin Bešlo · September 25, 2015
Hello!

I have to solve a problem. I hope someone can help me....

"Write a function to async get data from server.
Get JSON data from http://jsbin.com/funimefupo.js and with callback call the data"

Hope you understood what my problem is :D

Post a Reply

Replies

Oldest  Newest  Rating
0 Bram Dekker · September 25, 2015
What did you do to solve the problem yourself? Do you have example code that you wrote? Did you look at references? Perhaps promises might be an idea? We are not here to solve problems but to help you solve the problem :)
0 Brotsky Tv · September 26, 2015
Read this articles might that help you !!


1) Write a function to async get data from server.
2) https://docs.nodejitsu.com/articles/getting-started/control-flow/how-to-write-asynchronous-code


For more Javascript tutorials :  https://www.brotsky.tv/category/javascript/
0 Marin Bešlo · October 2, 2015
Yea, I did it, but it's not an async function, how could I write it?


var xmlhttp = new XMLHttpRequest();
var url = "http://jsbin.com/funimefupo.js";

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var arr = JSON.parse(xmlhttp.responseText);
            myFunction(arr);
}
}

xmlhttp.open("GET", url, true);
xmlhttp.send();

function myFunction(myArr){
for(var i in myArr.movies)
document.write(myArr.movies[i].Title + "");
}
+1 Bram Dekker · October 3, 2015
I see that you are using the XMLHttpRequest. Take a look here: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests :)
  • 1

Javascript

107,064 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators