When using web2py, how does JavaScript determine when all LOAD() components have finished loading?

I am currently facing a challenge in web2py where I need to load multiple separate forms onto a single web page using the {{=LOAD(...)}} function. My main concern is how I can trigger a JavaScript function once all of these forms have completed loading initially. Using .ajaxStop() causes the function to be executed every time one of the form components is submitted, which is not the desired behavior for my project.

Answer №1

After much thought, I managed to devise a practical solution for my specific scenario. In each LOAD() event, the sql table row id is used as a parameter. To handle this, I created an empty global javascript object named loaded at the beginning of the file. Then, while iterating over each row, I set properties in loaded to false:

    <script>var loaded = {};</script>
    {{for row in rows:}}
        <script>loaded['{{=row.id}}']=false</script>
        {{=LOAD('default','mycomponent.load', args=[row.id], ajax=True)}}
    {{pass}}

As each mycomponent.load component is processed, I mark it as loaded in the javascript array and check if all are loaded==true. For instance, at the conclusion of the mycomponent.load file:

<script>
    loaded['{{=row.id}}']=true; 
    if (Object.keys(loaded).every(function(k) {return loaded[k]}))
        function_to_execute_once_all_LOADs_done()
</script>

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

Develop a personalized function to enhance the standard jQuery $.ajax functionality

I am in need of developing a function that enhances jQuery's $.ajax callbacks. Specifically, I want to include default code in every beforeSend() and complete() callback. Here is an attempt I made: var custom = {}; var tempAjax = function(options,cal ...

Why won't XML load with jquery GET, but does load with a direct link and PHP?

When it comes to pulling in an xml feed, I've been experimenting with using php and simpleXML to load it. Interestingly, I can access the direct link without any issues. However, when attempting to utilize jquery and GET method, the request times out ...

Error: Attempted the use of 'append' method on an object lacking the implementation of FormData interface, with both processData and contentType set to false

Apologies for any English errors. I am attempting to use ajax to submit a form, and here is my JavaScript code: $("#formPublicidad").on('submit', function(event) { event.preventDefault(); var dataForm = new FormData(document.getElementBy ...

Activate dual AJAX JSON and cycle through multiple alerts each time an "ul li" element is clicked

In my code, I am utilizing two ajax requests. One retrieves a chat userlist column in JSON format, while the other fetches the message history for each user. The functionality works such that when a $('.member_list ul li') element is clicked, th ...

What could be causing my for loop to become unresponsive?

My for loop seems to be populating all fields with the last object parsed. http://codepen.io/anon/pen/EKxNaN This is my current code. I created something similar on CodePen since I can't access JSON from the original source there. var championMaste ...

Locating the specific row associated with a cell using jQuery

I’m new to programming and currently learning JQuery. I have a query: if there is a button in a column attribute, and upon clicking the button in that cell, I want to retrieve the unique ID value for that cell. For example, if my attribute name is "app ...

Tips on sending non-form values to an action in Struts 1.3 via AJAX

Here is a snippet of JSP code that I am working with: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> < ...

Display a loading bar or prevent any user interface actions until the server has finished generating the file

I am currently developing a force directed layout using d3.js on data retrieved from an MS SQL server database. I'm creating the json file with a python script and running it on a local server using python -m SimpleHTTPServer. My goal is to establish ...

JQuery appended Bootstrap Modal to Body, but it refuses to close

After going through the process of appending the modal to the body and getting the text box working, I encountered an issue when trying to close it on the AJAX success event - none of my attempted solutions seem to be effective. var id; var refundAmount ...

Comparison between JSON Serializers and .NET Serialized Classes for Retrieving jQuery AJAX Result Data

What is the best method for transferring data from a .NET (C#, VB.NET) Web Service to the client-side using JQuery AJAX? A) Utilizing Newtonsoft JSON serialization, for example: <WebInvoke(Method:="*", ResponseFormat:=WebMessageFormat.Json, UriTemplat ...

Steps on how to set the values of a select option based on a JSON parsed array

After receiving an array from a JSON call, I am trying to populate a select element with the data. {1:Android, 2:IOS, 3:Business Management Systems, 4:Database, 5:Codes/Scripts, 6:Others} or 1: "Android" 2: "IOS" 3: "Business Management Systems" 4: "Da ...

Troubleshooting Issue: XMLHttpRequest Incompatibility with Internet Explorer

I'm having an issue with the script below. It works fine on Firefox and Chrome but doesn't seem to work on IE. I've tried various solutions, including lowering the security settings on my browser, but it still won't work. function se ...

Autocomplete Data Origin

I'm currently exploring the use of Typeahead and implementing AJAX to fetch my data source: $(document).ready(function() { $('input.typeahead').typeahead( { hint: true, highlight: true, m ...

Guide to removing a duplicate footer generated by a Rails application due to the use of .load in jQuery/AJAX

Currently, I am utilizing jQuery/AJAX to dynamically load a page within my rails application using the code snippet shown below: $("#div1").load(url); The challenge I am facing is that the loaded page contains its own footer. As a result, when this div i ...

Having issues with ajax posting functionality

Is the following form correct? <form> <input type="submit" value="X" id="deleteButton" onclick="ConfirmChoice(<?php echo $id; ?>)" /> </form> Here is the function associated with the form: <script type='text/javasc ...

The value of form.__EVENTTARGET is undefined in JavaScript

When using my webforms.app on .net 4.0 and calling _doPostBack via aspx code <%= GetPostBackReference() %>; in the code behind protected string GetPostBackReference() { return Page.ClientScript.GetPostBackEventReference(ReloadThePanel,"null" ...

I'm having trouble with my dataTable creation using JQuery. Can anyone help me troubleshoot?

I've attempted various methods to make this work. Here's what I'm importing: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> <script type="text/javascript" src="https://cdn.datatabl ...

Jquery Ajax failing to retrieve a response

Here's the jQuery script I am using to fetch data from my server: $(".login_button").click(function () { var username = $(".username").val(); var userkey = $(".userkey").val(); $.ajax({ type: "GET", url: "http://192.168.0. ...

I am having trouble dealing with an integer AJAX response because when I try to alert it, all I get is [object, object]

$.ajax({ type: "POST", url: url_delete_admin_privilidge, data: postData, success: function(response) { console.log(response); setAdminResponse(response); alert("success") ...

Implement the HTML code for utilizing the GET method in an AJAX request

I'm exploring a way to utilize inline HTML directly as the URL for the ajax GET method without fetching data from a separate webpage. Is it feasible? Here is my ajax code: $.ajax({ type: "GET", url: $(elm).attr("href"), ...