2017-12-03 152 views
0

這是我迄今爲止通過使用Ajax嘗試的。問題在於我恢復了警覺(「出錯了!」)。我找不到解決方案。Ajax模態錯誤

的index.php

<?php 
    require_once 'core/init.php'; 
    include 'includes/head.php'; 
    include 'includes/navigation.php' ; 
    include 'includes/headerfull.php'; 
    include 'includes/leftbar.php'; 

    $sql ="SELECT * FROM products WHERE featured = 1 "; 
    $featured = $db->query($sql); 

?> 



<!---Main content---> 
<div class="col-md-8"> 
<div class="row"> 
<h2 class="text-center">Izdvojeni Proizvodi</h2> 
<?php while($product = mysqli_fetch_assoc($featured)) : ?> 

<div class="col-md-3"> 
    <h4><?= $product['title']; ?> </h4> 
    <img src="<?= $product['image']; ?>" alt="<?= $product['title']; ?> " 
class="img-thumb" /> 
    <p class ="list-price text-danger"> List Price <s>$<?= $product 
['list_price'];?></s></p> 
    <p class="price">Naša Cijena: $<?= $product ['price'];?></p> 
    <button type="button" class="btn btn-sm btn-success" onclick 
="detailsmodal(<?= $product ['id']; ?>)">Details </button> 
</div> 
<?php endwhile; ?> 

</div> 
</Div> 

<?php 
include 'includes/rightbar.php'; 
include 'includes/footer.php'; 
?> 

Footer.php

</div> 
<footer class ="text-center" id="footer">&copy; Copyright 2017-2018 Lodi 
</footer> 

<script> 

function detailsmodal(id) { 
var data = {"id" : id} ; 
jQuery.ajax({ 
url : 'includes/detailsmodal.php', 
method : "post" , 
data : data, 
success : function(data){ 
jQuery ('body').append(data); 
jQuery ('#details-modal').modal('toggle'); 
}, 
error: function(){ 
alert ("Something went wrong!"); 
} 
}); 

} 
</script> 

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> 
</script> 
<!-- Include all compiled plugins (below), or include individual files as 
needed --> 
<script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
</script> 


    </body> 
    </html> 


    </body> 
    </html> 

詳細modal.php

<!--Details Modal ---> 
<? ob_start(); ?> 
<div class="modal fade details-1" id="details-modal" tabindex="-1" 
role="dialog" aria-labelledby="details-1" aria-hidden="true"> 
<div class ="modal-dialog modal-lg"> 
<div class="modal-content"> 
<div class="modal-header"> 
<button class="close" type="button" data-dismiss="modal" aria-label="Close"> 
<span aria-hidden="true">&times;</span> 
</button> 
<h4 class="modal-title text-center">Levis Jeans</h4> 
</div> 
<div class="modal-body"> 
<div class="container-fluid"> 
<div class="row"> 
<div class="col-sm-6"> 
<div class="center-block"> 
<img src="images/headerlogo/levis.jpg" alt="Levis Jeans" class="details img-responsive"> 
</div> 
</div> 
<div class="col-sm-6"> 
<h4>Details </h4> 
<p>These jeans are amazing! They are straight leg,fit great and look sexy. 
</p> 
<hr> 
<p>Price: $34.99</p> 
<p>Brand: Levis</p> 
<form action="add_cart.php" method="post"> 
    <div class="form-group"> 
    <div class="col-xs-3"> 
     <label for="quantity"> Quantity: </label> 
     <input type="text" class="form-control" id="quantity" name="quantity"> 


    </div> 
    <p>Availabe: 3</p> 
    </div><br><br> 
    <div class="form-group"> 
     <label for ="size">Size:</label> 
     <select name="size" id="size" class="form-control"> 
     <option value=""></option> 
     <option value="28">28</option> 
     <option value="32">32</option> 
     <option value="36">36</option> 
     </select> 
    </div> 
</form> 

</div> 
</div> 
</div> 
</div> 
<div class="modal-footer"> 
<button class="btn btn-default" data-dismiss="modal">Close</button> 
<button class="btn btn-warning" type="submit"><span class="glyphicon 
glyphicon-shopping-cart"></span>Add To Cart</button> 
</div> 
</div> 
</div> 
</div> 
<?php echo ob_get_clean(); ?> 

的init.php

<?php 

$db= mysqli_connect('sql***.byethost11.com','****','****','ecom24database'); 
if (mysqli_connect_errno()) { 
echo'Database connection failed with following errors: ' . mysqli_connect_error(); 
die(); 

} 

define ('BASEURL','/ECOMDva'); 

我已經設置了導航欄和情態動詞的產品數據庫。 你可以看到網站在這裏上的錯誤: ​​

回答

0

您好我訪問了您的網站在Bytehost(freehosting)運行時,你有403 403訪問的詳細否認錯誤modal.php,這可能是因爲一些免費託管拒絕權限的文件爲Ajax請求,請更改文件夾權限 plese see this 和下一次寫你的Ajax誤差函數這樣會提醒你出現錯誤

function detailsmodal(id) { 
var data = {"id" : id} ; 
jQuery.ajax({ 
url : 'includes/detailsmodal.php', 
method : "post" , 
data : data, 
success : function(data){ 
jQuery ('body').append(data); 
jQuery ('#details-modal').modal('toggle'); 
}, 
error: function(xhr, textStatus, errorThrown){      
        alert("fail"+errorThrown); 
} 
}); 
+0

謝謝您的回答。我一直在使用Windows,並用FilleZilla上傳文件。我不確定我在哪裏更改文件夾權限。服務器響應此錯誤(禁止)此功能 – Lodix

+0

http://www.dummies.com/web-design-development/wordpress/navigation-customization/how-to-change-file-permissions-using-filezilla-on -your-ftp-site /請按照這些說明並將文件夾權限更改爲755 –

+0

我嘗試使用Cpanel,Chmod和現在的Filezilla,但它仍然是禁止的 – Lodix

0

負載jquery.min.js bootstrap.min.js.Like之前文件:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
+0

那麼它是在bootstrap.min.js之前,你可以看到footer.php內,這是行不通的 – Lodix