获取单个数据JQUERY

Imagine I have 3 data in my tbl_customer then If I click the button view, the modal will show with the data's. It's working if the button I clicked has data, Then the problem is, if the button has no data the modal didn't show. But I want to show the modal even I have no data in my button. Please help me out of this problem, thankyou!

Button: <button type="button" onclick="return chk('.$row['id'].')" class="btn btn-warning btn-xs">Add features</button>

Here's the code:

<script src = "http://code.jquery.com/jquery-1.9.1.js"></script>'

<?php 
$db = mysqli_connect("localhost", "root", "", "psbr");
$rooms_f = mysqli_query($db, "SELECT * FROM room_f"); 

while($row = mysqli_fetch_assoc($rooms_f)) { ?> 
<button type="button" onclick="return chk('.$row['id'].')" class="btn btn-warning btn-xs">Add features</button>
<?php } ?>

  function chk(id)
  {
    var roomid = document.getElementById('text_id_' + id).value;
    var dataString = 'roomid='+ roomid;
    $.ajax({
      type: "post",
      url: "fetch_single3.php",
      data:dataString,
      cache:false,
      success: function(data){

       $("#modal_features").hide();
       $("#modal_sample").slideDown();
       $("#modal_sample").html(data);
      }
    });
    return false;
  }

fetch_single3

    <?php 

$db = mysqli_connect('localhost', 'root', '', 'psbr');
$rooms = mysqli_query($db, "SELECT * FROM rooms");

    $roomid = $_POST['roomid'];
    $query = mysqli_query($db, "SELECT * FROM room_f WHERE room_id='$roomid'"); 

?>
<link rel="stylesheet" type="text/css" href="css/feature-design.css">
<div id="modal_sample">
    <h4 class="h4" style="margin: 3%;">Room Features</h4>
    <button class="btn btn-info button">Add Feature</button>
<table id="features_table">
  <tr>
    <th width="20%">ID</th>
    <th width="49%">Feature</th>
    <th>Action</th>
  </tr>
<?php while ($row = mysqli_fetch_array($query)) { ?>
  <tr>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['feature']; ?></td>
    <td><button class="btn btn-warning btn-xs">Update Feature</button> &nbsp;<button class="btn btn-warning btn-danger btn-xs ">Delete feature</button></td>
  </tr>
  <div class="add_modal" id="add_modal">
        <h4 style="margin: 5%; ">Add Feature</h4>
        <hr>
        <label style="margin: 1%;">Enter Feature name</label>
        <input type="text" id="text_featurename" name="text_featurename">
        <input type="hidden" id="text_featureid" name="text_featureid" value="<?php echo $row['room_id']; ?>">
        <input type="submit" name="submit" value="Submit" onclick="return add()" id="submit">
        <button class="btn btn-default cbtn_addm">Close</button>
    </div>
  <?php } ?>
</table>
<button type="button" id="btn_c"class="btn_c">Close</button>
</div>
dsbezji539113152
dsbezji539113152 这段代码根本无法工作。您正在关闭按钮上方的行上的PHP标记,然后尝试在chk中使用PHP变量('。$row['id']。')。单击按钮肯定会导致Javascript错误。
大约 2 年之前 回复
dongzhugao9929
dongzhugao9929 我已经更新了,请帮我解决这个问题!!:(
大约 2 年之前 回复
dongxian3418
dongxian3418 “如果我点击的按钮有数据”它正在工作“哪个按钮?上面的代码中有很多按钮。
大约 2 年之前 回复
drcigvoy48900
drcigvoy48900 我不知道对不起:(
大约 2 年之前 回复
doubaoguo7469
doubaoguo7469 是它响应错误代码(200)并发送任何响应数据?
大约 2 年之前 回复
duanji5116
duanji5116 我已经检查过了
大约 2 年之前 回复
duanpendan8067
duanpendan8067 没有错误。
大约 2 年之前 回复
dongqiaolong9034
dongqiaolong9034 它是否会引发任何错误?,请在浏览器中检查网络选项卡和控制台,以了解任何错误都在增加
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐