How to filter another page result with Jquery Load() or Get()?

Asked

Viewed 71 times

0

In an HTML have for example:

<fieldset>
    <div>
        <h3 class="title title-line">Dados da conta</h3>
    </div>

    <div class="ch-form-row">
        <label>Usuário</label>
        <span>MEU-USUARIO</span>

        <a class="smalla" href="https://myaccount.mercadolivre.com.br/profile/changeNickName">Modificar</a>
    </div>

    <div class="ch-form-row">
        <label>E-mail</label>
        <span>[email protected]</span>
        <a class="smalla" href="https://myaccount.mercadolivre.com.br/profile/changeEmail">Modificar</a>
    </div>

    <div class="ch-form-row">
        <label>Senha</label>
        <span>**********</span>
        <a class="smalla" href="https://accountrecovery.mercadolivre.com.br/accountrecovery/changePassword">Modificar</a>
    </div>
</fieldset>

I need Another page to capture the Username and save to a variable, as close as I can reach with jQuery Load() was:

$( "#id-de-teste" ).load("https://myaccount.mercadolivre.com.br/profile .ch-form-row span:first", function(data, status){
username = $('#retorno_webtracker').html();
alert(username);
    });

However I had 2 problems: The variable with the Username also got the tags <span>, and I don’t want/need this value to be displayed on the page, I just need it in the variable to proceed with the script routine.

With jQuery Get() can "download" the page with the data I need, however I am not able to filter only the class . ch-form-Row after the first tag

$.get("https://myaccount.mercadolivre.com.br/profile", function(data, status){
        //alert("Data: " + data + "\nStatus: " + status);
//username = $('span',$('.ch-form-row')).html();
filtro = data.getElementsByClassName('ch-form-row');
console.log( filtro );
    });

1 answer

0

I managed to solve

$.get("https://myaccount.mercadolivre.com.br/profile", function(data, status){
        var username = $('.ch-form-row span', $(data)).html();
//todo o codigo que precisa da variavel
});

Browser other questions tagged

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