Error with Jquery and html alert

Asked

Viewed 227 times

1

I’m making an alert with jquery.... its function is to show the user the error and depending on the action lead to a following page... well already tested and the error is in jquery because when I put the alert in pure html it appears perfectly inserir a descrição da imagem aqui

this example above is with html... the way it should appear.

Let’s go to code

$(document).ready(function(e) {

var  site = {

fechar: function(parametro){
    $('#alerta-preto').fadeOut(2000);
    $('#alerta-base').fadeOut(2000)
    location.href="http://www.site.com.br/"+parametro+"";
    }

alerta: function(conteudo,diretorio){
html = '';
html += '<div id="alerta-preto"></div>';
html += '<div id="alerta-base">';
html += '<div id="alerta-topo">Alerta <div id="alerta-fechar" onclick="site.fechar("'+diretorio+'")"></div></div>';
html += '<div  id="alerta-branco">';
html += '<div class="titulo"><b>Ops,</b> Alerta</div>';
html += ''+conteudo+'';
html += '</div>';
html += '</div>';   
$('#alerta-fly').append(html);
}
}
});

is +- so to call

//apenas para mostrar
site.alerta('Dados incorretos.','nao');
//para direcionar
site.alerta('Logado com sucesso.','inicio');

the problem is that it doesn’t work.... I checked that code every so often and it is well in my view...

  • Leandro is there any error message to show? Put so that we can help you.

  • this alert is an error action of type : the user has erroneous the password ... here appears that box -- Incorrect data...

  • Okay you run and it doesn’t look right?

  • gives some error in console?

  • I’ve already found some mistakes, I’m creating an answer

  • blz.. I can check in the console why the server gave pal BY PURE KNOWLEDGE

Show 1 more comment

1 answer

0


First, your functions within the site variable can be executed in any context of the site. So you cannot restrict it within the $(Document). ready

Below follows the code for testing

Note: I commented on the method to direct, to perform the test uncompromisingly the same.

var site = {
    fechar: function(parametro){
        $('#alerta-preto').fadeOut(2000, function (){
                $('#alerta-base').fadeOut(2000, function (){
                    if(parametro != undefined) {
                        location.href="http://www.site.com.br/"+parametro+"";
                    }
                });  
        });
    },
    alerta: function(conteudo,diretorio){
        var html = '<div id="alerta-preto"></div>';
        html += '<div id="alerta-base">';
        html += '<div id="alerta-topo">Alerta <div id="alerta-fechar" onclick="site.fechar("'+diretorio+'")"></div></div>';
        html += '<div  id="alerta-branco">';
        html += '<div class="titulo"><b>Ops,</b> Alerta</div>';
        html += conteudo;
        html += '</div>';
        html += '</div>';   
        $('#alerta-fly').html( html );
    }
}

$(document).ready(function(e) {
    //apenas para mostrar
    site.alerta('Dados incorretos.');
    //para direcionar
    // site.alerta('Logado com sucesso.','inicio');
});
  • perfect man thanks... you don’t know how much you’ve helped me.. I realized that I don’t know about jquery anymore q the time n arrange... Vlw continues like this!

  • I don’t remember if it’s forbidden to indicate paid books here in the community, but it follows the link from a great book. It is very practical and helps a lot, study Java Script as well. http://www.novatec.com.br/livros/jquery3ed/

Browser other questions tagged

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