weixin_33726313 2017-06-02 16:42 采纳率: 0%
浏览 20

ajax事件未发布数据[重复]

This question already exists:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/44327551/change-event-not-firing-on-ajax-loaded-elements" dir="ltr">change event not firing on ajax loaded elements</a>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-06-02 17:05:42Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

I have a 2 ajax call. First ajax call populates the dropdown box which works correctly, bu the second ajax call uses change event function. Whenever the dynamically populated item from the dropdown is clicked it lists the products details with image.

In below code the change function triggers becos it alerts the data item selected. but the problem starts inside the ajax i guess. so i am not getting the result(product details)

Problem: it donot list the products

also how to use var_dump($_POST) to check name1 is passed correctly

second ajax code:

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$("#name").on('change',function (e) { 
    var name1 = this.value;
    alert("name1 = " + name1);
    $.ajax ({
        data:{name1: name1},
        type: 'POST',
        url: 'dataprod.php',
        success: function (response) {
            console.log(response);

            $('.products-wrp').html('');
            $('.products-wrp').hide();
            $('.products-wrp').html(response);
            $('.products-wrp').show();            
        },
    });
});
</script> 

dataprod.php

<?php
$name1 = $_POST['name1'];
$results = $mysqli_conn->query("SELECT product_name, product_desc, product_code,  
product_image, product_price FROM products_list where product_name='$name1'");

$products_list =  '<ul id ="products_list" class="products-wrp">';
while($row = $results->fetch_assoc()) {
$products_list .= <<<EOT
<li>
<form class="form-item">
<h4>{$row["product_name"]}</h4>
<div>
<img src="images/{$row["product_image"]}" height="62" width="62">
</div>
<div>Price : {$currency} {$row["product_price"]}<div>
</form>
</li>
EOT;
}
$products_list .= '</ul></div>';
echo $products_list;
?>      
</div>
  • 写回答

1条回答 默认 最新

  • weixin_33704234 2017-06-02 16:45
    关注

    Try this code:

    ...
    url: '/dataprod.php'
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog