[英]Why can't I load html content (from a php file) inside the page?
I want the content of the page chosen by select to be loaded into the ajax-container div, but this is not working, why?我希望select选择的页面内容加载到ajax-container div中,但这不起作用,为什么?
index.php索引.php
<!doctype html> <html lang="pt-BR"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>INTRANET - REDES UNIPAM</title> <link rel="stylesheet" type="text/css" href="../css/style.css" /> <link rel="stylesheet" href="../css/bootstrap.min.css" /> <script src="../js/bootstrap.min.js"></script> <script src="../js/jquery-3.5.1.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> </head> <body> <div id="menu"> <?php include("../menu.php");?> </div> <div class="main"> <div class="container"> <div class="row"> <div class="col-6"> <fieldset class="scheduler-border"> <legend class="scheduler-border">Redes do UNIPAM</legend> <select id="mySelect" class="custom-select"> <option selected>Selecionar rede</option> <option><a class="ajax-click" href="index_bloco_a.php">Bloco A</a></option> <option><a class="ajax-click" href="index_bloco_b.php">Bloco B</a></option> </select> </fieldset> </div> </div> <div class="row"> <div class="col-6" id="ajax-container"> </div> </div> </div> </div> <script> $('.ajax-click').click(function(e) { var $clickedElement = $(this), pageToLoad = $clickedElement.prop("href"); $('#ajax-container').load(pageToLoad, function() { alert('Conteudo carregado com sucesso'); }); e.preventDefault(); }); </script>"; </body> </html>
index_bloco_a.php index_bloco_a.php
<table width="1500px" border="0" align="center">
<tr> <td align="center" bgcolor="#EAEAEA"><titulo><strong>BLOCO A</strong></titulo></td> </tr>
</table>
<table align="center" border="0" cellpadding="8">
<tr align="center"> <td> <a href="bloco_a_geral.php"> GERAL </a> </td> </tr>
<tr align="center"> <td> <a href="bloco_a_auto_atendimento.php">AUTO ATENDIMENTO </a> </td> </tr>
</table>
I wondered if it was because the <script>
tag was inside a php file, and I tried putting it inside a <? Php echo "<script> </script>"?>
我想知道是不是因为
<script>
标签在一个 php 文件中,我试着把它放在一个<? Php echo "<script> </script>"?>
<? Php echo "<script> </script>"?>
, But that was just the blank page. <? Php echo "<script> </script>"?>
,但这只是空白页。
";
from </script>";
";
from </script>";
This will work better这样效果会更好
$("#mySelect").on("change", function() {
const pageToLoad = this.value;
if (pageToLoad) {
$('#ajax-container').load(pageToLoad, function() {
console.log('Conteudo carregado com sucesso');
});
}
})
<select id="mySelect" class="custom-select">
<option value="" selected>Selecionar rede</option>
<option value="index_bloco_a.php">Bloco A</option>
<option value="index_bloco_b.php">Bloco B</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.