Javascript 为什么我的jqueryajax请求不能工作错误:未定义索引:ProID?

Javascript 为什么我的jqueryajax请求不能工作错误:未定义索引:ProID?,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,详细信息:嘿,伙计们,我到处寻找我的问题的解决方案,但是没有用,请不要报告问题,直到你理解我的问题。我有一个索引页面,其中包含sql,我拉它将产品添加到我的页面,并希望创建一个ajax请求,每个产品的id在按钮中回响,以创建一个产品详细信息页面,但是我似乎无法将产品id发布在产品详细信息页面上。任何关于正确方向的帮助都将不胜感激。谢谢你 确切错误:注意:中未定义索引:id 第7行C:\xampp\htdocs\website\includes\product\u detail.php 我尝试过的

详细信息:嘿,伙计们,我到处寻找我的问题的解决方案,但是没有用,请不要报告问题,直到你理解我的问题。我有一个索引页面,其中包含sql,我拉它将产品添加到我的页面,并希望创建一个ajax请求,每个产品的id在按钮中回响,以创建一个产品详细信息页面,但是我似乎无法将产品id发布在产品详细信息页面上。任何关于正确方向的帮助都将不胜感激。谢谢你

确切错误:注意:中未定义索引:id 第7行C:\xampp\htdocs\website\includes\product\u detail.php

我尝试过的事情: 将“post”更改为“post” 添加一个数据类型 这就是我看到的所有错误

Jquery代码:

功能详细信息(ProID){
变量数据={“id”:ProID};
jQuery.ajax({
url:“/website/includes/product_detail.php”,
方法:“张贴”,
数据:数据,
成功:功能(数据){
open(“includes/product_detail.php”,“_self”);
},
错误:函数(){
警惕(“出错时的事情!”);
}
});
}
HTML/php代码:

    <?php 
    require_once 'dbconnect/dbconnect.php';
      include 'includes/head.php';
      include 'includes/header.php';
      include 'includes/navigation.php';
      include 'includes/footer.php';

    $sql = "SELECT * FROM products WHERE featured = 1";
    $featured = $db->query($sql);
?>
    <div class="main-content">
        <div  class="main-body">
            <h2 class="center-header">Featured Products</h2>
            <?php while($product = mysqli_fetch_assoc($featured)): ?>
                <div class="row_one">

                    <div class="product-one" >
                        <h4><?= $product['ProName']; ?></h4>
                        <a href="includes/product_detail.php">
                        <img class="product_img_one"src="<?= $product['Image']; ?>" alt="<?= $product['ProName']; ?>">
                        </a>
                        <p>List Price:<s class="list_price">$<?= $product['List_Price'];?></s></p>
                        <p>Sales Price:$<?= $product['Price'];?></p>
                        <button type="button" class="product-detail" 
                                onclick= "detail(<?= $product["ProID"]; ?>)">Details</button>

                </div>
             <?php endwhile; ?>
          </div>
        </div>

    </div>

</body>
</html>

特色产品
标价:$

售价:$

应该是

 $id = $_POST["id"]; not  $id = $_POST["ProID"];
在您的product_detail.php页面上

应该是

 $id = $_POST["id"]; not  $id = $_POST["ProID"];

在你的product_detail.php页面上,我怀疑jquery ajax使用的方法是
方法:'POST'
POST应该用大写字母

// this is what i am using as template for sending request after organizing data in json format...
$.ajax({
        method: "POST",
        url: "submit.php",
        data: {Product_Name: "theProduct_Name", Price: 500, "Product_ID": "theProduct_ID"},
        success : function(responseText)
                  {
                    alert('success to reach backend');
                    // you can console the responseText and do what ever you want with responseText
                    console.log(responseText);
                  },
        error : function(jqXHR, status, error)
                {
                    if (jqXHR.status === 0) 
                    {
                        alert('Not connected.\nPlease verify your network connection.');
                    } 
                    else if (jqXHR.status == 404) 
                    {
                        alert ('The requested page not found. [404]');
                    } 
                    else if (jqXHR.status == 500) 
                    {
                        alert ('Internal Server Error [500].');
                    } 
                    else if (exception === 'parsererror') 
                    {
                        alert ('Requested JSON parse failed.');
                    } 
                    else if (exception === 'timeout') 
                    {
                        alert ('Time out error.');
                    } 
                    else if (exception === 'abort') 
                    {
                        alert ('Ajax request aborted.');
                    } 
                    else 
                    {
                        alert ('Uncaught Error.\n' + jqXHR.responseText);
                    }
                 }
      });

我怀疑jqueryajax使用
方法的方法:“POST”
POST应该用大写字母

// this is what i am using as template for sending request after organizing data in json format...
$.ajax({
        method: "POST",
        url: "submit.php",
        data: {Product_Name: "theProduct_Name", Price: 500, "Product_ID": "theProduct_ID"},
        success : function(responseText)
                  {
                    alert('success to reach backend');
                    // you can console the responseText and do what ever you want with responseText
                    console.log(responseText);
                  },
        error : function(jqXHR, status, error)
                {
                    if (jqXHR.status === 0) 
                    {
                        alert('Not connected.\nPlease verify your network connection.');
                    } 
                    else if (jqXHR.status == 404) 
                    {
                        alert ('The requested page not found. [404]');
                    } 
                    else if (jqXHR.status == 500) 
                    {
                        alert ('Internal Server Error [500].');
                    } 
                    else if (exception === 'parsererror') 
                    {
                        alert ('Requested JSON parse failed.');
                    } 
                    else if (exception === 'timeout') 
                    {
                        alert ('Time out error.');
                    } 
                    else if (exception === 'abort') 
                    {
                        alert ('Ajax request aborted.');
                    } 
                    else 
                    {
                        alert ('Uncaught Error.\n' + jqXHR.responseText);
                    }
                 }
      });

更改
$id=$\u POST[“ProID”]
$id=$\u POST['id']@dass我已经试过了,但它不起作用,谢谢你的建议,为什么要使用
jQuery.ajax({
?使用
$.ajax({
@dass我认为它与$.ajax相同,但我刚才也尝试过更改它,但它仍然没有帮助解决错误。代码仍然是
$id=$\u POST['id']
或你改回来了??将
$id=$\u POST[“ProID”];
改为
$id=$\u POST['id'];
@dass我已经试过了,但它不起作用,谢谢你的建议,为什么要使用
jQuery.ajax({
??使用
$.ajax({
@dass我认为它与$.ajax相同,但我刚才也尝试过更改它,但它仍然没有帮助解决错误。代码仍然是
$id=$\u POST['id']
或您已更改回??谢谢您的建议,但我的数据库中的id是ProID。我还是尝试了,但没有成功。请检查ProID值是否已正确从数据库中获取。请使用打印($product);旁边是while loopHey Arup我尝试了这个,也尝试了使用和alert在每次单击产品详细信息按钮时向我显示该产品的ID,并显示ID感谢您的建议Arup,但我数据库中的ID是ProID。我还是尝试了,但它不起作用。您能检查ProID值是否从dat正确获取吗使用印刷品($product);下一步,虽然loopHey Arup我尝试了这一点,也尝试了使用和警报来显示我的ID每次我点击一个产品详细信息按钮来显示该产品的ID,它显示idlet我知道它是否对你不起作用如果起作用请接受作为一个答案…?它不起作用谢谢你的建议。感谢!如果它不起作用,请告诉我rk如果有效,请接受作为回答…?它不起作用,谢谢你的建议。谢谢!