Pass PHP parameters to Jquery Mobile Panel

Asked

Viewed 86 times

1

Good morning to all,

I’m trying to do a function where a JQM Panel dynamically receives a PHP page with some parameters. However it does not work, the panel opens blank. Below is the code I am using:

     $(".botao").on("mouseup", function (e) {
        var url = $.ajax({
                      method: "GET",
                      url: "menu.php",
                      data: { qtd: "1", linhas: "19" }
                    });     
        opendialog(url);
    });

    function opendialog(page) {
        $("#menu").html(page);
        $("#menu").trigger('updatelayout');
        $("#menu").trigger('create');
        $("#menu").panel("open");
    } 

I have also used . GET instead of . AJAX in the code, also unsuccessfully.

Thanks in advance for the help.

  • Bro, you shouldn’t have the method success in the $.ajax and from it you would call opendialog?

1 answer

2


Try to do this way, so you have in Success how to assign the return of the ajax call. Check with the console.log(return) command what will return from this url you are accessing and perform the assignment to the #id menu elements as you wish. After the return of Success it will call the Trigger and panel in the complete. If there is an error in the ajax call you can deal with the error.

 $(".botao").on("mouseup", function (e) { 
    $.ajax({
        url: "menu.php",
        method: "GET",
        data: { qtd: "1", linhas: "19" },
        error: function(XMLHttpRequest, textStatus, errorThrown){
           console.log("Trate o Error neste ponto!");
        },
        success: function(retorno) {
            console.log("se tiver duvida do que está retornando: " + retorno);
            $("#menu").html(retorno);                   
        },      
        complete: function(){
            $("#menu").trigger('updatelayout');
            $("#menu").trigger('create');
            $("#menu").panel("open");
        }
    });      
});
  • It worked Fernando, thank you very much! Just one more question, which code would be the equivalent of the "onclose" of this panel?

Browser other questions tagged

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