Engage with it to access the get feature

Looking for help with updating information in a websql database using a function. Currently, I'm facing an issue where the loading box closes before the get function completes its task, leading to incomplete updates.

I need a solution where the next iteration of the loop only occurs once the get function has finished executing.

If anyone has a workaround for this, please share your thoughts! :(

The technology stack I'm working with includes appframework intel (jqmobi).

for (var i=0; i<len; i++){
    var url = "http://172.25.129.30:8180/prax/rest/ocorrenciaJSONBean/consultarStatusOcorrencia/"+results.rows.item(i).id;
    $.get(url,function(data){
        tx.executeSql('UPDATE ocorrencias SET status="'+data.responseText+'" WHERE id = '+results.rows.item(i).id);
    });
};

Here's the situation:

We have an internal database containing a list of user-opened calls. The goal is to update the status of these calls.

Currently, I fetch each call's status from a webservice based on their ID from the internal database. However, I want the next iteration to only proceed once the GET request has been completed.

The challenge lies in the fact that the loading message disappears too soon, before all the GET requests have been finalized.

Answer №1

In order to ensure your get function performs the next call without waiting, you will need to implement a callback within the function. One way to achieve this is by using the following code:

var index = -1;
function perform_get(){
    index++;
    var url = "http://172.25.129.30:8180/prax/rest/ocorrenciaJSONBean/consultarStatusOcorrencia/"+results.rows.item(index).id;
    $.get(url,function(data){
        tx.executeSql('UPDATE ocorrencias SET status="'+data.responseText+'" WHERE id = '+results.rows.item(index).id);
    })
    .done(perform_get);
}

With this implementation, each get call will now be executed in sequence without delay.

I hope this explanation proves helpful.

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

Issues with loading cascading drop down list data from database using MVC, JSON, and C#

Hello everyone, I'm fairly new to MVC/Javascript and have been experimenting with different tutorials in order to create a cascading drop down list for selecting State and City on an MVC view. In my latest attempt, I followed this example. While the ...

How to display JSON object in JSP using Ajax code

I am attempting to print a JavaScript object using AJAX on the client side (.jsp), but I keep getting an error. Here is my code in the servlet: response.setContentType("application/json;charset=utf-8"); JSONObject json = null; try { json = ...

Having trouble adding global method using Plugin in Vue 3?

I have been working on creating a method that can generate local image URLs to be used in any template automatically. However, I encountered an issue while trying to develop a plugin that adds a global property. Plugin Implementation: // src/plugins/urlb ...

Having trouble displaying the output on my console using Node.js

Hey there, I'm new to this community and also new to the world of nodejs technology. I have encountered a problem that may seem minor to you but is quite big for me. Here's what's going on: In my code snippet, I want a user to input 3 value ...

What could be causing my JSON product list to not load properly?

My list is not loading and I can't figure out why. I've included my json, jquery, and HTML below. The console isn't showing any errors, but the list is still blank. Any help would be greatly appreciated as I am new to working with json. Than ...

Regenerating the session leads to expired sessions when making quick AJAX requests

My web application is primarily built on an AJAX framework using the Codeigniter Framework and a memcached session handler. One challenge I have encountered is that when my application sends numerous asynchronous calls, the session ID sometimes needs to b ...

Ways to include dots in a D3 chart?

I'm striving to create a graph that includes lines and dots. Although I have successfully drawn lines and dots with zoom and brush functionalities, the issue arises when I try to zoom in or out - the dots do not adjust accordingly. Being relatively ...

Struggling to update local state with response data when utilizing hooks in React

I am a beginner using Functional components and encountering an issue with setting the response from an API to a local useState variable. Despite receiving the response successfully, the variable remains empty and I am struggling to figure out how to resol ...

The functionality of Ajax is not supported on browsers of Android devices

I'm facing an issue where some Android devices do not support the ajax function I am using to check the username and password. What steps should I take to resolve this problem? Below is the code for my ajax function: $(function() { $("#loginfor ...

Retrieve the value associated with the data attribute of the chosen dropdown option

I need to extract the custom data attribute from the chosen option of a dropdown menu and insert it into a text box. This will be the second data attribute I'm working with. I plan to implement code that will run whenever the user changes the option ( ...

What is the process for determining the files array in the nx dep-graph?

With each new release of NX v16.1.4, the file node_modules/.cache/nx/nxdeps.json is created. The structure of this file differs from the one generated by nx graph. In previous versions up to 16.1., the file contained an array named nodes.<app/lib>.d ...

Prevent overlapping of nodes and edges in a D3 force-directed layout

Check out this fascinating example at http://bl.ocks.org/mbostock/1747543: In the demonstration, Mike illustrates how to prevent nodes from colliding with each other in a graph. I'm curious if it's feasible to also prevent collisions between no ...

What alternative can be used for jquery isotope when JavaScript is not enabled?

Is there a backup plan for jQuery isotope if JavaScript isn't working? For instance, if I'm using the fitColumns feature, is there an alternative layout style available in case JavaScript is disabled, similar to what is seen on the new Myspace? ...

I am experiencing an issue with my service provider when it comes to displaying multiple navigator stacks

Currently, I am developing a provider to manage the user's state across different views. The primary function of this provider is to display either one stack navigator or another based on whether a certain variable is filled or empty. This setup allow ...

When transitioning in Vue, pagination bullets shift to the left upon changing routes

While using Vue 3 and swiper.js, I encountered an issue where the pagination bullets move to the left when the route changes (component unmounted). It appears that the styling for the bullets and active button also disappear. I have created a reproduction ...

Auto-complete feature not populating the input field in Google Chrome

Within my register form, I have various INPUT tags present. One of these INPUTs has the name email. <input type=text name=email id=email> When filling out this form in Chrome, I encounter a peculiar behavior. Upon clicking on the email input field ...

Remove location markers on Google Maps v3 store locator upon selecting a different distance option

I have been struggling to make my code work even after looking at similar solutions. I am working on a feature where a user enters their postcode and selects a distance in miles from a dropdown to view stores on a Google map using Ajax in MVC. The issue I ...

Using ng-repeat to pass a parameter into a function triggered by ng-click

Check out the code snippet provided: <div> <div class="list-group"> <a class="list-group-item" ng-click="c.selectItem(note.sys_id)" ng-repeat="note in data.notes"> <h4 class=& ...

What techniques can I use to generate a 3D visual effect by shifting the background image layer as the user scrolls (creating a Parallax effect

I have combined two images in the heading; one on top of the other. My goal is to create a subtle vertical movement in the background image as the user scrolls, giving the illusion of depth. Both images share the same width, but the background image is tal ...

Tips for extracting tables from a document using Node.js

When converting an XML document to JSON using the xml-js library, one of the attributes includes HTML markup. After parsing, I end up with JSON that contains HTML within the "description":"_text": field. { "name": { ...