how to implement jquery in php?

Asked

Viewed 1,517 times

-1

good afternoon my doubt and the following I want to put a custom jquery confirm Alert in php code but it does not run already tried everything already called the files and nothing if anyone can help thank you

here is my code the section where I want to put jquery inside an echo:

echo"<script>alert('Nenhum Resultado Encontrado'), window.open('index.php','_self')</script>";

I tried to use it like this:

                    echo"<script>$.alert({
    title: 'Alert!',
    content: 'Simple alert!',
    confirm: function(){
        alert('Confirmed!');
    }
});, window.open('index.php','_self')</script>";
  • 1

    Here worked normal the first code, see in your devTool at console if an error appears.

  • 1

    php is the server-side language and javascript is the client-side (browser). You should use ajax for this.

  • Vish do not know how to use ajax as q I can do it this way? could you explain me rray?

  • The use of ajax seems to have nothing to do with the case..

  • 1

    I think he just wants a custom dialogbox... but I think the use of $.alert because it does not exist natively. And also the fact of parsing a static code in PHP, seems meaningless or unnecessary.

  • If you wanted a "custom jquery Alert", you should look for the method dialog(): http://jsfiddle.net/eraj2587/Pm5Fr/14/

  • people I have already found a jquery plugin that makes the custom Alert I tested it using only javascript or better saying the jquery it is running this learning the bunitinha Alert but I want to implement it in an echo in php and can not and that I want not dialog box.

Show 2 more comments

1 answer

1

Good afternoon,

Edited: From what I understand you want to give an alert to the user that what he searched for was not found. You should have a page like www.lovedevelopment.com.br/vusca.php? q=0 ( q=0 and did not find the result ). In this case we will see how it would look in php.

<?php 
   //Analisando o caso com a URL ww.lovedevelopment.com.br/vusca.php?q=0
   //vamos primeiro colocar em uma variável o resultado
   $testa_minha_busca = $_GET['q'];
    //Depois vamos testar se o resultado veio igual a 0
   if ( $testa_minha_busca == 0 ) {
       //Se for encontrado vamos mandar um alerta 
       echo "<script>alert('Sua busca tá osso man!');</script>";
       // Em seguida vamos mandar ele para home e 3 segundos
       header( "refresh:3;url=home.php" ); 
}
?>

I saw that one of the tips they gave you was to use AJAX. Let’s first start using this "Disinfectant".

What is it ? Method that opens a window to pass client-side information to the server-side.

And when do I wear this ? I want to save my data in a mysql database and I have a file that inserts it into the database an Insert.php only that the data is coming from a client-side form and I don’t want to use the PHP POST.

Let’s take an example in a search. I have a file that calls check_de_busca.php and I want but I want the search to be dynamic and without Reload, and the data comes from javascript. And when the result is null it returns this file calls check_de_search.php.

  <script>
  $(document).ready(function() {
      //Quando clicar na busca
    $('botao_buca').click(function() {
        //chama o AJAX
      $.ajax({
          //vamos postar
        type: "post",
        //Para o Arquivo abaixo
        url: "check_de_busca.php",
        //A variável do javascript que eu quero passar para o PHP é termo de busca
        data: "busca"+termo_de_busca,
        //Asynchrono
        async: true,
        //Se ele der sucesso da requisição e for 0 avisa os truta
        success: function(result) {
          if (result == 0) {
            alert('Sua busca tá osso man!');
          }
        },
      });
    });
  });
</script>

Just adjust your variables and Divs. And an additional interface tip if you’re going to send an alert ( http://t4t5.github.io/sweetalert/ ).

Thank you,

I’m available

  • let me see if I mean then I co put that script where my Alert code is in php echo? And I’m also not sure about these url: something dates: something could explain me exactly what your code is doing?

  • 1

    an expert understands what he wanted to give you.. but also understands that it is not a suitable thing because it just leaves a confused person even more confused..

  • Daniel, you’re absolutely right, my response was based on my day-to-day, I’m sorry. I edited the answer so that it is more complete and with more tips. I am working to learn how to answer here at Stackflow

Browser other questions tagged

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