簡體   English   中英

為什么我不能在頁面內加載 html 內容(來自 php 文件)?

[英]Why can't I load html content (from a php file) inside the page?

我希望select選擇的頁面內容加載到ajax-container div中,但這不起作用,為什么?

索引.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

<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>

我想知道是不是因為<script>標簽在一個 php 文件中,我試着把它放在一個<? Php echo "<script> </script>"?> <? Php echo "<script> </script>"?> ,但這只是空白頁。

  1. 您需要在引導之前加載 jQuery
  2. 你想刪除"; from </script>";
  3. 選擇不能包含鏈接

這樣效果會更好

$("#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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM