Run php on click, with jQuery

Asked

Viewed 64 times

0

I’m trying to do a function with jQuery (I saw it once in jQuery), where when clicking on a link, runs a php page in the background. Note: I am not good with jQuery.

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
    $(document).ready(function(){
      $("#botao").click(function(){
        //apenas executa uma página após o click do usuário final em um botão.
        //nada é feito além de execução da página, nenhum aviso, nada.
        //não é enviado qualquer parâmetro para para pagina.php.
        //permanece na página atual sem qualquer alteração.
        $função_que_executa_pagina: 'pagina.php';
      }); 
    });
  </script>
</head>
<body>
    <!--botão que executa o código-->
    <a id="botao" href="#">
  </body>
</html>

I tried so it didn’t work.

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
    $('#botao').on('click', function () {
     url = 'pagina.php';
     var aClasse = this.id;
     $.ajax({
       url: url,
     }
    });
  });
  </script>
</head>
<body>
    <!--botão que executa o código-->
    <a id="botao" href="#">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js">
  </body>
  </script>
</html>

If anyone can help, I’d appreciate it.

  • 1

    What exactly is your problem? Edit your question and provide us with more information like the corresponding HTML, where you define this variable Purl...

  • Márcio, where the variable comes from purl? What you want to pass to PHP?

  • What do you want with url : 'pagina.php'? What do you expect me to do? If you don’t know say you don’t know, but it’s hard to figure out what you want...

  • Yes, I took this code on the Internet and tried to edit, because I don’t understand jQuery (no javascript).

  • want to run page.php so that it changes the notification status to 'viewed'.

  • I have something exactly like Facebook notifications, when clicking to see, already mark as viewed.

  • I also wish it was duplicated, but it has nothing to do with the other post. I don’t want to load a page on another, just run a php page without leaving the page you are on, without the end user perception.

  • It’s exactly the same thing @Márcioteixeira

  • Use Ajax! There is no page update this way, the browser makes the request without giving Reload.

  • I reread the question and did not identify similarity. I know that I am not clear, because I do not know the commands of jQuery. I changed the question to try to clarify.

  • How to do in Ajax? Marcelo Aymone.

  • 2

    It is not an exact duplicate at all, but the answers there serve almost entirely for your case. Use an ajax call that is in the accepted answer of the other question, and change only what is within the function of success (what is to be done after receiving a php response; it may be nothing).

  • Exactly how you put @bfavaretto...

  • I think his problem is that he declared the reference to jQuery after using the function $.

Show 9 more comments
No answers

Browser other questions tagged

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