$. ajax stops working the other jquery scripts

Asked

Viewed 148 times

0

Use this function to call a page:

$('#selector1').on('change',function(){
    $.ajax({
            type      : 'post',
            url       : 'servico_institucional.php', // aqui eu indico qual o arquivo que vai ser enviado essa variavel retorno
            data      : 'retorno='+$("#selector1").val,  //Cara, aqui eu pego o valor do input com o ID AJAX_INPUT E passo para uma variavel chamada    retorno
            dataType  : 'html',
            success : function(response){
                $('.form-servico').html(response);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                    alert("Erro!");
            }
    }); 
});

However, when I call the page, the other scripts jquery stop working. Example: menu scripts, responsiveness among others.

How to fix this problem?

  • try to pass on your date, the value like $("#selector1"). val()

  • Must be giving js an error. You’ve debugged?

1 answer

1


Speak, Diego! Blz?

Use Eval() to run scripts.

$('#selector1').on('change',function(){ 
    $.ajax({
        type: 'post',
        context: document.body,
        url: 'servico_institucional.php',
        data: 'retorno='+$("#selector1").val,
        dataType: 'html',
        success: function(response){
            $('.form-servico').html(response);
            $('.form-servico').find('script').each(function(i) {
                eval($(this).text());
            });
        }, error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("Erro!");
        }
    });
});

If you have questions about how the function works, see this W3schools article: http://www.w3schools.com/jsref/jsref_eval.asp

Hug!

  • I’m having a similar problem here: http://answall.com/q/146486/7759 but I don’t know how to do it, in my case I will have to call the file rodape.inc.php (where the scripts are) whenever I change URL via ajax?

Browser other questions tagged

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