Get a certain part of html from another javascript page

Asked

Viewed 1,192 times

0

Hello everyone wanted to get a specific area of what this coming from the other page for example what comes from the other page I get the div with id as I would do this with my script?

<script type="text/javascript">
        // Função responsável por atualizar as frases
        function atualizar()
        {
            // Fazendo requisição AJAX

$('#mensagensinbox').load("functions/atumensainbox.php?id_log_ass=<?php echo $id_log_ass;  ?>");


        }
        // Definindo intervalo que a função será chamada
        setInterval("atualizar()", 10000);
        // Quando carregar a página
        $(function() {
            // Faz a primeira atualização
            atualizar();
        });
    </script>

1 answer

1

Good evening Gezer, you need to know the transponders that you want to pick up inside the html returned by $.load().

Note that the html returned by $.load() will be charged in the div #mensagensinbox.

Then just find the transponders inside #mensagensinbox.

Imagine that the html of the page that was loaded return:

<!-- muitos outras tags acima -->
<div class="mensagens">
   <span class="titulo"> Boa noite</span>
   <p class="mensagem">Oi, como vai você, queria te desejar boa noite.</p>
</div>
<!-- muitas outras tags abaixo -->

For you to take a specific content within all these tags that were returned, it would look something like this:

var mensagens = $("#mensagensinbox").find(".mensagens");

Finally, if you give one console.log(mensagens[0]); you will realize the following html.

<div class="mensagens">
<span class="titulo"> Boa noite</span>
<p class="mensagem">Oi, como vai você, queria te desejar boa noite.</p>
</div>

To conclude, within all content returned in the function load, you just took the div containing the class .messages.

I hope I’ve helped.

  • Now that I’ve remembered rsrs the load inside it I can put the id of the div for example $('#mensagensinbox'). load("functions/atumensainbox.php? id_log_ass=<? php echo $id_log_ass; ? > #essadiv");

  • Yes, but I believe in the same way, the return of the contents of load will continue to be the entire content of the page functions/atumensainbox.php. You must pick up the content after return. UPDATE - If you use the # you only take the content of that identifier.

  • 1

    solved he just got the div he really wanted got top now.

  • Interesting...

  • for example now it looks like $('#mensagensinbox'). load("functions/atumensainbox.php? id_log_ass=<? php echo $id_log_ass; ? > #messages"); calling another part $('#mensagensvalinbox'). load("functions/atumensainbox.php? id_log_ass=<? php echo $id_log_ass;? > #totalmessages");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.