2017-02-19 17:13
浏览 47


I have a list

<ul id="my_ul">
<li data-value="1"><a href="test.php">111</a></li>
<li data-value="2"><a href="test.php">112</a></li>
<li data-value="3"><a href="test.php">113</a></li>

I tried to pass the data-value on click event to MySQL query. I tried it with jQuery but when i var_dump the result its NULL.

Here is how i am getting the value

$('#my_ul').on("click", "li", function(){
   $.ajax("fetch_test.php",{method:"post", data:{val:$(this).attr("data-value")}}); 

and here is the fetch_test.php file code :

function showValue(){
include_once "connect.php";
$query="SELECT * FROM product INNER JOIN smetka on WHERE product.smetka_id=$test";
            $alert .="<li data-value='$row[id]'><a href='test.php'>$row[name]";

            $alert .= "</a></li>";
    return $alert;

How can i pass the data-value from the li?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题