Is it possible to monitor all Responses and Headers of the page to use as a trigger for a function?

1

I have a script that needs to be executed only after the return of a page request, since the request returns HTML content, and the function I want to execute immediately after it implements this received HTML. The problem is that I can not play other functions because my access is limited.

I already know that these requests are made when I click on the link that I called "TRIGGER" in the image, but the answers do not only come in very different times, but also change the return order because it is asynchronous.

I just need to recognize when 1st response (from the code I can not change) come to me, so I can run my script that brings the 2nd response / p>

MytemporarysolutionwastousesetTimeout()torunmy4secondsfunctionafterclickingontheTRIGGER(Mycourses)link,becausebymytests,evenwitha"reasonable" internet, gives time to receive all requests.

Below I show the header of the 1st answer. Would anyone have any idea what I could do?

    
asked by anonymous 25.10.2017 / 22:42

1 answer

1

You could use DOMSubtreeModified , however, according to documentations , it is being discontinued and it would not be advisable to use it.

What can be done, as a solution, is to create a setInterval that will be checking, after the set time, when a certain element exists on the page.

As we are not sure the elements of your page (your question does not provide such details), the concept below works and should be tailored to your code:

Let's suppose I have the following HTML:

<div>
   <div id="retorno">
      Texto etc...
   </div>
</div>

And Ajax inserts, as a return from the 1st response, the following code into the div "return":

<div id="resposta1">
    Esta é a resposta 1
</div>

After Ajax, HTML looks like this:

<div>
   <div id="retorno">
      <div id="resposta1">
         Esta é a resposta 1
      </div>
   </div>
</div>

With the script below, using setInterval , I would check when that div "answer1", returned from Ajax, would be present on the page (before Ajax it did not exist) and call the second function:

<script>
temporizador = setInterval(function(){
    if($("#resposta1")){
       clearInterval("temporizador"); // paro o setInterval
       // chamo a segunda função
    }
}, 1000); // de 1 em 1 segundo
</script>

So, to adapt the "timer" in the example above, you need to know which div is inserted only and exclusively in the Ajax return of the 1st response.     

26.10.2017 / 00:07