Ajax事件未发布数据 [英] ajax event not posting data

查看:80
本文介绍了Ajax事件未发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2 ajax调用.第一个ajax调用将填充可正常工作的下拉框,而第二个ajax调用将使用change event函数.每当单击下拉列表中的动态填充的项目时,它就会列出带有图像的产品详细信息.

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.

在下面的代码中,更改功能将触发触发,因为它会警告所选的数据项.但问题开始于我猜想的ajax内部.所以我没有得到结果(产品详细信息)

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)

问题:它没有列出产品

还如何使用var_dump($ _ POST)检查name1是否正确传递

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

第二个ajax代码:

<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

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;
?>      

推荐答案

尝试以下代码:

...
url: '/dataprod.php'
...

这篇关于Ajax事件未发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆