Error calling Java Script in HTML

Asked

Viewed 110 times

0

Ol, I’m doing a content load other pages without updating the masterpage with AJAX as follows:

Line that I click

<li id="pag1">Pag1</li>

Script

$("#pag1").click(function(){
  $.ajax({
type :"POST",
 async: false,
 url: paginadeconteudo.php",
}).done(function(data){
    $("#conteudo").html(data); 
});
}

inserir a descrição da imagem aqui

Until then everything 100%, it loads the page inside the other, loads the styles and everything, but does not load or call Jquery. For example in the mask in an X field. If I use this in the header of my master page, content can’t run, someone can explain why?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.11/jquery.mask.min.js"></script>

<script>
    $("#cpf").mask("000.000.000-00");
    $("#tel, #tel2").mask("(00) 00000-0000");
</script>

EDITED: This is an example of my code. the Page I’m calling n gets the same if I already reference directly within it. It gets paid if I enter the page and update, but if I leave and go back to work, it is as if ref. did not exist.
BS.: Try testing on a page . html local I think running from here is bugged!

<!DOCTYPE html>
<html>

<head>
  <title>teste</title>
  <style type="text/css">
    .pagina {
      max-height: 200px;
      background-color: white;
      color: black;
    }
    
    .menu {
      max-height: 200px;
      background-color: black;
      color: white;
    }
  </style>
    

</head>

<body>
  <div class="menu">
    <button class="add-usuario">CHAMAR PAGINA</button>
  </div>
  <div class="pagina" id="conteudo"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="meudiretorio/meuajax.js"></script>
  <script>
    $(".add-usuario").click(function() {
      $.ajax({
        type: "POST",
        async: false,
        url: "https://www.doraziosportes.com.br/cadastrarusuario.php",
      }).done(function(data) {
        $("#conteudo").html(data);
      });
    });
  </script>
</body>

</html>

  • Your question is very confusing, but on all pages that use jQuery you will have to insert the jQuery files by following the positions (1º - jQuery, 2º - plugins using jQuery).

  • Obg, but I’ve done all the jquery references

2 answers

0

Place the script on the page of your "paginadeconteudo.php" content, including the Mask, jquery, and return:

echo '<script>
    $("#cpf").mask("000.000.000-00");
    $("#tel, #tel2").mask("(00) 00000-0000");
</script>';

Since you are using jquery, I should change this ajax to this:

<script>
    $(".add-usuario").click(function() {
      $.post('https://www.doraziosportes.com.br/cadastrarusuario.php', {dado: '1'}, function(data){
        $("#conteudo").html(data);
      })
    });
  </script>
  • Obg, but I’ve done all the references and no funf.

  • I edited the answer, dude you have to call this script on the other page, or load it in callback function, the script can NOT be loaded before the return of the content page.

  • I edited my question from a look.

  • You need to allow the file to be accessed, put it in the first line of the code of your page registering user.php " header('Access-Control-Allow-Origin: *'); "

-2

Try using jquery load(), or throw the references in the file loading the other pages.

Browser other questions tagged

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