Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
how to detect XMLHttpRequest and add function

I'm working on php project,

I have 2 pages, data is synchronized between pages using XMLHttpRequest .

When i click button on the first page, the dom in the second page is updated .

I have this function :

function getAlertes(popup) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() { //Action en réponse de la requête
        if (this.readyState == 4 && this.status == 200) {
            if (popup) {
                document.getElementById("popup-container").innerHTML = this.responseText;
            } else {
                document.getElementById("listAlertes").innerHTML = this.responseText;
            }
            toggleListInvisible();
        }
    };
    // Préparation et envoi de la requête au serveur
    xmlhttp.open("GET", "../../private/controller/action_list_alertes.php?popup=" + popup, true);
    xmlhttp.send();
}

This js script allow to add a div eatch time a button is clicked :

enter image description here

How can i fetch the data eatch time an XMLHttpRequest is detected in the destination page ?

I tried this :

function getAlertes(popup) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() { //Action en réponse de la requête
        if (this.readyState == 4 && this.status == 200) {
            if (popup) {
                document.getElementById("popup-container").innerHTML = this.responseText;
                const audio = new Audio("../audio/BELLDoor_Doorbell.wav");
                audio.play();
            } else {
                document.getElementById("listAlertes").innerHTML = this.responseText;
            }
            toggleListInvisible();
        }
    };
    // Préparation et envoi de la requête au serveur
    xmlhttp.open("GET", "../../private/controller/action_list_alertes.php?popup=" + popup, true);
    xmlhttp.send();
}

i need to play sound when the dom is updated by in this cas the sound is played for every XMLHttpRequest.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!