Creating a loader with a built-in timeout feature in JavaScript

I am retrieving data from an API and managing the loading of the data using a loader in my HTML. If the data array length is undefined, the data will be displayed. However, if there is no data, it continues to load indefinitely... My goal is to implement a timeout feature for situations where there is no data available. For example, after 10 seconds of waiting, I want to display a message like "No data found."

Check out my Vue.js template below: https://i.sstatic.net/5hdD8.png

Answer №1

Looking for a way to display a message after 10 seconds? Check out this example:

function showDelayedMessage(newState) {
  setTimeout('', 10000); //10sec * 1000

  if(newState == -1) {
    alert('ERROR: No data available');
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The window.open() function is malfunctioning on Google Chrome

Within my vue.js application, I have encountered an issue when attempting to utilize window.open() to open a new tab. Strangely, whenever I use this method, the new tab opens briefly before immediately closing without loading any content. Surprisingly, win ...

Validating date parameter in Wiremock request - How to ensure dynamic date matching during testing?

Looking for some assistance in verifying that the date in a request is exactly Today. I've tried various methods from the documentation, but haven't achieved the desired outcome yet. Calling out to any helpful souls who can guide a junior QA thro ...

What is the best way to create a list from a matrix using JavaScript?

I have an array structured as follows: const input_array= [ ["red", "green"], ["small", "medium"], ["x", "y", "z"] //... can have any number of rows added dynamically ...

Listening to a sequence of mp3 tracks consecutively

I'm currently working on a project that involves playing a series of mp3 files consecutively. However, I've encountered an issue with my code snippet below: Here's the code snippet: function playAudio(){ var au = document.getElementById( ...

Changing divider color in Material-UI with React

I need some assistance with changing the color of the divider component from the material ui framework. I have successfully changed colors for other components using the useStyles() method like this: const useStyles = makeStyles(theme => ({ textPad ...

How to retrieve a specific value using jQuery based on the name attribute

I'm having an issue retrieving the selected value from the menu and assigning it to the `country` variable. Whenever I try, I keep encountering the error: No parameterless constructor defined. The `UpdateClient` function is triggered by clicking on t ...

What is preventing me from using javascript setInterval with a function in a separate external file?

Everything is running smoothly with this code snippet...an alert pops up every 10 seconds <script type='text/javascript'> function letsTest(){ alert("it works"); } var uptimeId = window.setInterval(letsTest, 10000); < ...

"MongoDB fails to save changes when attempting to remove an item from an updated

I've been using Angular Fullstack for a web application. When I send my data using $http.post(), I include the following object: { title: "Some title", tags: ["tag1", "tag2", "tag3"] } However, when I edit the object and try to update it with $http ...

Verifying user authorization for Microphone access prior to triggering event in React application

I have created a React component featuring a microphone button that operates as follows: OnMouseDown => Initiates audio recording by the user OnMouseUp => Ceases audio recording To elaborate, while the button is pressed down, the user can continue ...

Using Vuetify to create a dynamic datatable populated with data from an

I am currently facing an issue with populating a datatable using an axios call. Even though the data is present in the table when inspected, it is not visible to the end user on the site. Can anyone offer any insights into what might be going wrong here? ...

Nuxt's dynamic route generation results in a 400 error status code

Currently integrating Nuxt with my app and aiming to establish a connection with my server to retrieve data. To create dynamic routes, I am utilizing the built-in generate method but facing some challenges. Upon executing the generate command, I encounte ...

What is the reason for receiving an undefined value when calling getInitial

In my index page like this: function Index({posts}) { console.log(posts); return ( <div> Homepage {/* {posts && posts.length > 0 && posts.map(post => <h1 key={post._id}>{ post.title} ...

The output of the http.get or http.request callback is only visible within the shell when using node.js

Just dipping my toes into node and aiming to avoid falling into the callback hell trap. I'm currently working with two files: routes.js fetch.js //routes.js var fetchController = require("../lib/mtl_fetcher/fetcher_controller"); var express = requir ...

Images obscure dropdown menu

The issue I am experiencing with my blog is that the dropdown menu is appearing behind the image slider on the main page. You can see it here: Can anyone offer guidance on how to prevent this from happening so that the dropdown menu is not obscured? Just ...

After refreshing the page, Angular 8 may incorrectly load JavaScript from an incorrect path when accessing a lazy loaded

Whenever I refresh the page while on a lazy loaded module, the application breaks because it attempts to import JavaScript files from an incorrect path. Here is an overview of my routing configuration: App Routing Module: { path: 'accommodations&ap ...

How to pass a data property as a function argument in Vue.js

Instead of using a few methods that are structured like this: showDiv1(){ this.showDiv1 = true }, showDiv2(){ this.showDiv2 = true } I am attempting to consolidate them into one method like so: showElements(...elementNames){ elementNames. ...

Incorporate duration into date using angular

In my Firebase database, I store the following information: Timestamp for the day a record was created in Firebase. Terms entered by the user at the time of creation. For instance, it may look like this: 1439612582756 // converts to: Aug 14, 2015 15 / ...

Utilize AJAX to showcase JSON data retrieved from a specified URL

We are striving to showcase the names listed in our JSON file within a div using JavaScript. Despite multiple attempts, we have not yet achieved success. JSON data: This is the approach we took: <button>fetch data</button> <div id="result ...

AJAX - Alert with a beep sound each time a new entry is inserted into the database table

Having trouble determining the condition to test for when a new record is added to the database table. Can anyone lend a hand? Here's a snippet of the data retrieved from the database: ['Paul Abioro', '<a href="/cdn-cgi/l/email-prot ...

Issue encountered when trying to import an image URL as a background in CSS using Webpack

I have been trying to add a background image to my section in my SCSS file. The linear gradient is meant to darken the image, and I'm confident that the URL is correct. background-image: url(../../assets/img/hero-bg.jpg), linear-gradient(r ...