Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
storing Api JSON Data into localstorage js

I'm trying to save Api JSON Data into local-storage js,but still when I reload the page all data I'm trying to save in local-storage disappear.

Here is the code:

const mealList = document.getElementById("meal");
mealList.addEventListener("click", getMealRecipe);

function getMealList() {
    let searchInputText = document.getElementById("search-input").value.trim();

    fetch(`https://www.themealdb.com/api/json/v1/1/filter.php?i=${searchInputText}`)


    .then(response => response.json())
        .then(data => {
            let html = "";
            localStorage.setItem("proInCart", JSON.stringify(data.meals));
            let prog = JSON.parse(localStorage.getItem("proInCart"));

          

            if (data.meals) {
                
                data.meals.forEach(meal => {
                    html += `<div class="meal-item" data-id="${meal.idMeal}">
                     <div class="meal-img">
                     <img src="${meal.strMealThumb}" alt="">
                    </div>
                    <div class="meal-name">
                     <h3>${meal.strMeal}</h3>
                    <a href="#" class="recipe-btn">Get Recipe</a>
                    </div>
                    </div>`
                })

                mealList.classList.remove("notFound");
            } else {
                if (localStorage.getItem("sorry")) { html = localStorage.getItem("sorry") } else {
                    localStorage.setItem("sorry", "sorry,We didnt find any meal!");
                    let sorry = localStorage.getItem("sorry");
                    html = localStorage.getItem("sorry");
                }


                mealList.classList.add("notFound");
            }
            let progg = JSON.parse(localStorage.getItem("proInCart"));
            if (localStorage.getItem("html")) { mealList.innerHTML = localStorage.getItem("html") } else {
                localStorage.setItem("html", html);
                let hhtml = localStorage.getItem("html");
                mealList.innerHTML = localStorage.getItem("html");
            }
            mealList.innerHTML = html;

        });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!