Ways to include a notification if the information cannot be retrieved from the backend within 50 seconds (AngularJS)

Hello everyone,

I have a question regarding setting a message if the server does not respond within 50 seconds. I am using an AngularJS factory to send requests to the server.

$http.post("https://example.com/_ah/api/tweeting/v1/xxx?average_cycle=1&date_last_stroke=2001-01-01&do_last_bp_measaure="+do_last_bp_measaure+"&googleusername="+window.localStorage.getItem('username_google')+"")
.success(function(response){
  alert(response);
}, function(error){
  alert(error);
})

I have tried using $timeout but I am still unable to receive a message back.

Answer №1

Discover how $http handles timeout configuration:

timeout – {number|Promise} – specifies the timeout length in milliseconds, or a promise that will cancel the request upon resolution.

For instance:

    $http.post(
    "https://example.com/_ah/api/tweeting/v1/xxx?average_cycle=1&date_last_stroke=2001-01-01&do_last_bp_measaure="+do_last_bp_measaure+"&googleusername="+window.localStorage.getItem('username_google')+"",
    {
        'postData': 'whatever'
    },
    {
        'timeout': 50000 // 50 seconds
    }
    )
    .success(function (response) {
        console.log("Response received within 50 seconds :)");
    })
    .error(function (response) {
        console.log("Request timed out :("); // Other errors are possible as well
    });

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 template literal expression is being flagged as an "Invalid type" because it includes both string and undefined values, despite my cautious use of

I am facing an issue with a simple component that loops out buttons. During the TypeScript build, I encountered an error when calling this loop: 17:60 Error: Invalid type "string | undefined" of template literal expression. In my JSX return, I ...

Issues with angular ui.bootstrap functionality not functioning as expected

Having some difficulty implementing the popover element in an Angular application using ui.bootstrap. Here is a snippet of the code: In the app.js file, I include ui.bootstrap: angular.module('developerPortalApp', [ 'ui.bootstrap' ...

Next JS restricts XLSX to return only 100 objects as an array of arrays

I've developed a file upload system that reads Excel files and uploads data to a database (using Mongoose). After implementing the code, I noticed that when I use console.log(sheetData), it returns an array of arrays with objects inside. Each internal ...

How can I add content using HTML or JavaScript?

How can I append a .txt file using HTML or Java without ActiveX prompts getting in the way? It's becoming quite annoying! Is there a simple way to script this task without having to deal with ActiveX? The current script snippet looks something like ...

An issue occurred while attempting to read words from JSON file

My current issue involves loading words from JSON into my webpage. The images are functioning properly, thankfully. I have already successfully loaded the necessary images through JSON onto my webpage. However, I am still in need of loading words through ...

When using NodeJS with expressJS, remember that req.body can only retrieve one variable at a

I'm having trouble with my login and signup pages. The login page is working correctly, but the signup page is only transferring the password for some reason. App.JS: var express = require("express"); var app = express(); var bodyParser = require("bo ...

The output is: [object of type HTMLSpanElement]

<form> <table> <tr> <td>Distance:</td> <td><input type="number" id="distance" onKeyUp="calculate();">m</td> </tr> <tr> <td>Time:</td> ...

Is there a messaging app that provides real-time updates for when messages are posted?

I am in the process of developing a messaging application. User1 sends out a message, and I want to display how long ago this message was posted to other users - for example, "Posted 9 min. ago", similar to what we see on sites like SO or Facebook. To ach ...

Preserve data on page even after refreshing in Angular

Upon opening my website, I expect to see "Finance/voucher" at the top. However, after refreshing the page, only "Finance" appears which is not what I want. I need it to always display "Finance/voucher" even after a page refresh. I have included all the r ...

Creating unit tests for a state that includes PreparedQueryOptions within Jasmine framework

Currently, I am in the process of writing a Jasmine test case for the state within Angular JS. The resolve section of my state looks something along these lines: resolve: { myResult: function () { var dfd = $q.defer(); ...

Stop users from refreshing or closing the window while an axios request is being processed

I'm in the process of creating a dynamic Web Application that involves utilizing Axios.get requests. Given that Axios operates asynchronously, my approach includes an async function along with await axios.all: async handleSubmit(){ const ...

`There is a lack of props validation in the react/prop-types``

As I set up my Next-React app on Netlify, I encountered an error in the deploy log: Netlify deploy log indicates: "Error: 'Component' is missing in props validation", "Error: 'pageProps' is missing in props validation" within my ./page ...

Unable to toggle AngularJs Divs with <select> tags

In my view, I have the following code: <div> <select ng-model="chartType" ng-change="AnalyticsChartTypeChanged(chartType)" ng-init="chartType='Data grid'"> <option value="Data grid">Data gri ...

Is there a way to tally ng-required errors specifically for sets of radio buttons?

Currently, I am working on a form in AngularJS that includes groups of radio buttons. One of my goals is to provide users with an error count for the form. However, I have encountered a peculiar issue: After implementing this code to keep track of errors ...

Having trouble with Angular 2 and localhost/null error while attempting to make an http.get request?

In my Angular 2 webpage, I am using the OnInit function to execute a method that looks like this (with generic names used): getAllObjects(): Promise<object[]>{ return this.http.get(this.getAllObjectsUrl).toPromise().then(response => response. ...

How to append a JSON object to an existing .json file

UPDATE: Despite successfully executing the PHP code, my JSON file remains unchanged. I must apologize in advance for covering old ground, but I have spent countless hours exploring different solutions with no success. Perhaps sharing my challenge could as ...

Having trouble exporting CSV files with Tamil fonts. Are you experiencing an error?

We are exploring various methods to display Tamil content in a CSV file with characters like "தூதுக்கடட". Can anyone provide assistance? mysqli_set_charset($db, "utf8mb4"); $query = $db->query("$reports"); if($query->num_rows > ...

Struggling to include the VividCortex angular-recaptcha dependency in the AngularJS module due to an

Struggling to integrate Google reCaptcha v2 into my AngularJS app. I attempted to utilize VividCortex's angular-recaptcha, but incorporating the dependency into my app module proved challenging. The current code within my module looks something like ...

Open a fresh window using Javascript and add new content inside

After creating a script that opens a window and writes content when the button is clicked once, I noticed that clicking the button again causes the window to gain focus instead of rewriting the content. Does anyone have any ideas on how to fix this issue ...

Fetching information from the server in response to the data transmitted from the client

In need of help with sending a string id from the client to server side and retrieving related information using Node.js for the back-end. I have searched online but haven't found a solution yet. Hoping this isn't a redundant question. ...