2017-04-10 73 views
1

我已經制作了一個我想用jQuery .load()函數加載的模板。測試時我發現它不會加載任何內容。jQuery .load()不會加載我的腳本

這裏是我的加載代碼:

function open() { 

      history.pushState(null, null, "artiesten.php?u=Chato De Veirman"); 

      $('.content').load('artiest_template.php .content'); 

     } 

這裏是我的模板代碼:

<?php include('includes/connect.php') ?> 
    <span class="content"> 

    <div class="right_col" role="main"> 

    <div class=""> 
    <script>alert("nothing")</script> 
<div class="row" id="groot"> 
     <div class="col-md-4 col-sm-2 col-xs-12 profile_details"> 
     </div> 
     <div class="col-md-4 col-sm-8 col-xs-12 profile_details"> 
        <div class="well profile_view"> 
         <div class="col-sm-12"> 
         <h4 class="brief a-titel"><i>Panda 2.0</i></h4> 
         <div class="left col-xs-7"> 
          <h2 class="a-naam">Laurent Meersman</h2> 
          <p><strong>Over: </strong><span class="a-over"> Te weinig tijd/Grafische artiest/Gek </span></p> 
          <ul class="list-unstyled"> 
          <li><i class="fa fa-user"></i> Kernmerk: <span class="a-kernmerk">Gek</span></li> 
          <li><i class="fa fa-envelope-o"></i> Email: <span class="a-email"><a href= "mailto:[email protected]">[email protected]</a></span></li> 
          </ul> 
         </div> 
         <div class="right col-xs-5 text-center"> 
          <img src="images/Laurent Meersman.jpg" alt="" class="img-circle img-responsive a-foto"> 
         </div> 
         </div> 
         <div class="col-xs-12 bottom text-center"> 
          <button type="button" class="btn btn-info btn-xs"> 
          <i class="fa fa-video-camera"> </i> Bekijk meer video's. 
          </button> 
        </div> 
        </div> 

     </div> 
     </div> 
     <div class="row" id="klein"> 
     <div class="col-md-2 col-sm-2 col-xs-12 profile_details"> 
     </div> 
     <div class="col-md-8 col-sm-8 col-xs-12 profile_details"> 
        <div class="well profile_view"> 
         <div class="col-sm-12"> 
         <h4 class="brief a-titel"><i>Panda</i></h4> 
         <div class="left col-xs-7"> 
          <h2 class="a-naam">Laurent Meersman</h2> 
          <p><strong>Over: </strong><span class="a-over"> Te weinig tijd/Grafische artiest/Gek </span></p> 
          <ul class="list-unstyled"> 
          <li><i class="fa fa-user"></i> Kernmerk: <span class="a-kernmerk">Gek</span></li> 
          <li><i class="fa fa-envelope-o"></i> Email: <span class="a-email"><a href= "mailto:[email protected]">[email protected]</a></span></li> 
          </ul> 
         </div> 
         <div class="right col-xs-5 text-center"> 
          <img src="images/Laurent Meersman.jpg" alt="" class="img-circle img-responsive a-foto"> 
         </div> 
         </div> 
         <div class="col-xs-12 bottom text-center"> 
          <button type="button" class="btn btn-info btn-xs"> 
          <i class="fa fa-video-camera"> </i> Bekijk meer video's. 
          </button> 
        </div> 
        </div> 

     </div> 
     </div> 

     <?php 
     echo '<script>alert("' . $_GET['u'] . ' or nothing")</script>'; 
if($_GET['u']){ 
$t = mysqli_real_escape_string($connect,$_GET['u']); 
$res = mysqli_query($connect, "SELECT * FROM artiesten WHERE Naam='" . $t . "'"); 
$i = mysqli_fetch_assoc($res); 
echo ' 
    <script src="vendors/jquery/dist/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
     $(".a-titel").html("' . $i['Titel'] . '"); 
     $(".a-naam").html("' . $i['Naam'] . '"); 
     $(".a-over").html("' . $i['Over'] . '"); 
     $(".a-kernmerk").html("' . $i['Kernmerk'] . '"); 
     $(".a-email").html("' . $i['Email'] . '"); 
     $(".a-foto").attr("src", "images/' . $i['Naam'] . '.jpg"); 
     history.pushState(null, null, "?u=' . $i['Naam'] . '"); 
    }); 
    </script>'; 
} 
?> 



    </div> 

    </div> 

    </span> 

有人可以幫我嗎? 在此先感謝。

+0

爲什麼你有'.content'與您的負載函數的文件路徑? –

+0

@DiddleDot所以它只會加載我想加載的特定事物而不是刷新。 –

+0

Waarom staat「.content」achteraan in load()? 「.content」maakt geen deel uit van de URL。印度和其他地區的參數都會影響整個荷蘭()的水平。 – Kobbe

回答

0

應該是

function open() { 

     history.pushState(null, null, "artiesten.php?u=Chato De Veirman"); 

     $('.content').load('artiest_template.php'); 

    } 

function open() { 

     history.pushState(null, null, "artiesten.php?u=Chato De Veirman"); 

     $('.content').load('artiest_template.php .content'); 

    } 
+1

謝謝,它工作。 –

+0

歡迎您! – JBoy

0

jQuery的負載()有三個參數,URL,數據和功能。這些參數必須由昏迷分開。你的load()在你的URL後面有一些不是URL的一部分。

變化

$('.content').load('artiest_template.php .content'); 

$('.content').load('artiest_template.php'); 
+0

謝謝,它的工作。 –