首页 文章

在ajax成功后,div不输出php结果

提问于
浏览
0

我的主要表格上有一个div:

<div id="dynamic-content">RESULT</div>

将数据发送到php文件后通过ajax插入记录:

$.ajax({
    url: "test.php",
    type: "POST",
    data: {"mydata": myjson},
    dataType: "JSON",
    success: function (data) {

        $('#dynamic-content').html(''); // blank
        $('#dynamic-content').html(data); // load data
    }
});

并在php文件中插入mysql之后使用表作为结果:

<div class="table-responsive"> 
 <table class="table table-striped table-bordered">
  <tr>
  <th>PRODUCT</th>
  <td><?php echo $product; ?></td>
  </tr>
  <tr>
  <th>PRICE</th>
  <td><?php echo $price; ?></td>
  </tr>
  </table>
 </div>

“动态内容”div中没有任何内容 . 为什么?

1 回答

  • 0

    当您回显HTML时,您必须 dataType: "html" 因为您将其写为"json",AJAX将搜索 test.php 文件中不存在的JSON输出因此,编写 dataType: "html" 将解决您的问题

相关问题