Koooomo Koooomo - 25 days ago 5x
Ajax Question

How and where to save data I receive from an ajax call?

I'm doing an ajax request and I want to save data I receive from it on a page as oppossed to saving it in a variable. How can I do that?


If you want to keep the data in memory, you can use browser's local storage :


With local storage, web applications can store data locally within the user's browser.

// Store
localStorage.setItem("lastname", "Smith");

// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
Try it Yourself ยป

If you want to display the data on the page, you can use javascript to update the page e.g.

document.getElementById("result").innerHTML = ajaxResult;