What is the method to load iframes individually?


Trying to figure out a way to load 6 iframes on page A.php, each containing content from sub pages a1.php~a6.php. The catch is that before loading each sub page, an AJAX call needs to be made to update the database. Additionally, these sub pages must be loaded consecutively, one after the other - meaning a2.php can only load after a1.php has completely loaded. This poses timing issues especially considering the large size of each sub page. How can this functionality be achieved? Whenever a1.php isn't fully loaded, the AJAX in a2.php triggers and alters the datatable.
Any assistance would be greatly appreciated. Thank you!
JS:

function showpic(id,x,y)
{ 
    if (id==0)
    {
        var oBao = CreateHTTPObject();
        var url = "ajax.php";
        var sendstring="x="+x; 
        oBao.open("POST",url,false);
        oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        oBao.send(sendstring); 
        oBao.onreadystatechange = function () { OnReadyStateChng();};
        document.getElementById("iframe"+id).src="a.php?y=" +y;
    }
    else
    {
        var iid=id-1;
        document.getElementById("iframe"+iid).onload=function()
        {
            var oBao = CreateHTTPObject();
            var url = "ajax.php";
            var sendstring="x="+; 
            oBao.open("POST",url,false);
            oBao.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            oBao.send(sendstring); 
            oBao.onreadystatechange = function () { OnReadyStateChng();};
            document.getElementById("iframe"+id).src="a.php?y=" +y;
        }
    }
}

PHP:

for($i=0;$i<2;$i++)
{
    for($j=0;$j<3;$j++)
    {
        $nu=$i*3+$j;
        $div="iframe".$nu;
        echo "<iframe id='$div'  height='400px' frameborder=0 ></iframe>";
        echo "<script language='JavaScript'>showpic($nu,$x,$y) ;</script></div>";
    }
}

Answer №1

Apologies for not delving into your code, however, I found your explanation to be quite comprehensible. It's worth noting that an ajax request invariably includes a callback function, which is where you can retrieve the responsetext for your request. Within this unidentified callback function, you have the liberty to invoke another function that initiates the loading of the subsequent iframe. Simply adjust the src attribute of the frame and watch it load seamlessly.

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

Ensure that the textbox remains safe from accidental keyboard inputs

How can I ensure that users can only select a date from the calendar control in my textbox, rather than typing it manually, even if I make the textbox read-only? ...

The functionality to click an AJAX button using Selenium Webdriver (Java) is currently unavailable

I am having an issue with my website where I have buttons located at the top. Upon clicking these buttons, a new AJAX section is supposed to appear. The button "Add" is my target, but unfortunately it is wrapped in a <span> tag which is causing some ...

Is there a way for me to utilize the imported data from one component in the context API using an arrow function?

I am trying to utilize placeInfo, reviews, detailsInfo, news from a data file. Instead of using value='hello', I am unsure if I can directly use it like this: value={placeInfo, reviews, detailsInfo, news}, as it is producing an error. Should I st ...

Sort through the data that is already populated and proceed to paginate within Mongodb

Hey there, I'm currently working on populating some data and then implementing pagination for that data. Take a look at this example: Schema A (Users) { name: 'Demo', postId: 'someObjectId', } Schema B (Posts) { id: 's ...

Best practice for dynamically adding/storing/creating HTML elements on the fly

What is the best approach to dynamically add and store HTML controls for dynamically added elements on an HTML page? Currently, I am developing a widget-based system where users can choose which widgets they want to display. They have the flexibility to s ...

What is the average time frame for completing the construction of an electron project?

My project has only a few npm dependencies, but the build process is taking longer than 30 minutes and still counting. I'm not sure if this is normal or if there's an issue causing the delay. I have two specific questions: Is it common for pro ...

Instructions on how to extract a specific timestamp from a video and utilize it to initiate an event

Is there a way to trigger an event or animation at a specific time in a video or frame of the video? For instance, I want text to appear when a video reaches 30 seconds. I've experimented with currentTime, tried using loadeddata, and attempted to u ...

The module for the class could not be identified during the ng build process when using the --

Encountering an error when running: ng build --prod However, ng build works without any issues. Despite searching for solutions on Stack Overflow, none of them resolved the problem. Error: ng build --prod Cannot determine the module for class X! ...

The Firebase signInWithPopup functionality suddenly shuts down in a Next.js project

Incorporating the signInWithPopup function for signing in has been successful during the development stage on my local server. const firebaseAuth = getAuth(app); const provider = new GoogleAuthProvider(); const [{ user, cartShow, cartItems }, dispatc ...

Exploring the world of BDD with Node.js and Angular in an actual web

Currently, I am in the midst of developing an application using nodeJs + yo angular-fullstck, starting with BDD and TDD practices. After searching through multiple resources, I have decided to utilize cucumber-js and Jasmin with the karma runner for testi ...

Using the Google Maps API to display a map on two different HTML pages, but encountering an error on one of them

"Map: Expected mapDiv of type Element but was passed null." -The height of the div is set in the css. Javascript (googleMaps.js): function initMap() { try { const sportHall2 = { lat: 51.18310959584043, lng: 4.388290 ...

Tips for altering the color of string outputs

Can you help me modify a function to display different colors based on the output? For instance, I want it to show in orange if the result is too low, and in red if it indicates obesity. bmiCalculation() { var weight = parseInt(this.currentWeight); ...

Issues with three.js files: The identifier 'define' cannot be found, 'THREE' property is not recognized in the type, and 'set' property does not exist on an empty object

https://i.sstatic.net/LSy6T.png I recently obtained the three.js file with hopes of utilizing it, but I have encountered some errors within the file. Does anyone have any suggestions on how to troubleshoot and resolve these errors? ...

I'm curious about integrating Font Awesome into my React.js project - any tips on

I'm having trouble getting Font Awesome to display in my React JS project. Here is the code I am using: import React, {Component} from 'react' import './category.css' import axios from 'axios' import Course from './c ...

Getting a 404 error when attempting to go straight to a URL in a Single Page Node App

Currently, my setup involves a NodeJS backend connected to a ReactJS frontend (without utilizing create-react-app). To bundle both the React frontend and the Node backend, I am using webpack. The webpack configuration generates an "dist" directory in the ...

Finding the distance between two coordinates using Mapbox is easy once you understand how to utilize

Currently, I am in the process of learning how to utilize the Mapbox API within my node application. One of my objectives is to execute calculations on the backend, particularly obtaining the distance between two sets of coordinates. I'm struggling w ...

Linking query branches without encountering the "Exceeded the number of hooks rendered during the previous render" error

This apollo client utilizes a rest link to interact with 2 APIs. The first API returns the value and ID of a record, while the second API provides additional information about the same record. I combine this information to render the content without using ...

Adding nested JSON data to MySQL using NodeJS

My current challenge involves using Node.js to INSERT JSON data into a MySQL database. Everything runs smoothly until I encounter nested values within the JSON structure. Here is an example snippet of my JSON data: var result2 = [{ "id": 89304, "employe ...

Tips for looping through a JSON object?

Similar Question: How to extract a specific value from a nested JSON data structure? I am looking to loop through a two-dimensional JSON object, whereas I already know how to do so for a one-dimensional JSON object. for (var key in data) { alert(data ...

The dangers posed by vulnerabilities in the React library

Hi there, I just finished setting up react-redux and noticed some vulnerabilities showing up in my console - both low and high. Can anyone explain what this means and if I should consider uninstalling it? ...