gpt4 book ai didi

javascript - AJAX 调用失败,ReferenceError 分配给未声明的变量 PostRPC

转载 作者:行者123 更新时间:2023-11-29 19:58:14 32 4
gpt4 key购买 nike

我正在尝试使用 AJAX 函数使用数据库中的动态数据打开模式。但是当我点击按钮打开模态时我得到了

ReferenceError: assignment to undeclared variable PostRPC in category.php on line 3 col 2.

编辑

阅读Firefox document我了解此错误类型是因为已将值分配给未声明的变量。换句话说,存在一个不带 var 关键字的赋值。声明的变量和未声明的变量之间存在一些差异,这可能会导致意外的结果,这就是 JavaScript 在严格模式下出现错误的原因。我试图找到我的代码中哪里有未声明的变量,这很奇怪。

类别.php

        <!DOCTYPE html>
<html lang="en">
<head>
<script src="js/jquery.js"></script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script src="js/jquery-migrate-1.2.1.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="js/script.js"></script>
<script src="js/superfish.js"></script>
<script src="js/jquery.ui.totop.js"></script>
<script src="js/jquery.equalheights.js"></script>
<script src="js/jquery.mobilemenu.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.tooltipster.js"></script>
<script>
$(document).ready(function(){
$().UItoTop({ easingType: 'easeOutQuart' });
$('.tooltip').tooltipster();
});
</script>
<script>
$(function(){
$('#pull').on('click', function(e) {
e.preventDefault();
$('#menu').slideToggle();
});

})
</script>
</head>

<body>

<?php $sql = "SELECT * FROM product WHERE featured = 1";
$featured = $db->query($sql);
?>

<?php while($product = mysqli_fetch_assoc($featured)) : ?>
<div class="grid_4">
<a href="#"> <img src="images/page2_img1.jpg" alt=""></a>
<div class="text1"><a href="#">Product Name</a></div>
<a href="#"> 120.00$ </a>
<div class="alright"><button type="button" class="btn btn-sm btn-success" onclick="detailsmodal(<?php echo $product['id']; ?>)">See Product</button></div>
</div>
<?php endwhile; ?>

<!--==============================footer=================================-->
<?php include'/includes/footer.php'?>
</body>

页脚.php

    <script src="js/classie.js"></script>

<script src="js/thumbnailGridEffects.js"></script>
<script>
$(document).ready(function detailsmodal(id){
var data = {"id" : id};
jQuery.ajax({
url : "<?php echo BASEURL;?>+ '/MyProjectName/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>

最佳答案

对我来说解决问题的方法是在 footer.php 的 javascript 中为 BASEURL 设置不同的路径

而不是

  <script>
$(document).ready(function detailsmodal(id){
var data = {"id" : id};
jQuery.ajax({
url : "<?php echo BASEURL;?>+ '/MyProjectName/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>

    <script>
$(document).ready(function detailsmodal(id){
var data = {"id" : id};
jQuery.ajax({
url : "<?php echo BASEURL;?>+ '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>

对我来说,它解决了一切。因此,如果您碰巧遇到同样的问题,请修改您的路径,直到它适合您为止。这可能会有所帮助。

关于javascript - AJAX 调用失败,ReferenceError 分配给未声明的变量 PostRPC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40620714/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com