【发布时间】:2019-08-03 09:22:43
【问题描述】:
我正在尝试将一些 mySQL 数据加载到数据表中,以便轻松进行排序和搜索等... 我希望数据采用 div 的形式,这样我就可以轻松地了解它的外观。 我有以下代码,它会导致本文底部列出的错误。
index.php
<?php
include 'includes/SQL/connect.php';
include 'includes/structure/header.php';
?>
<script>
$('document').ready(function() {
$.ajax({
url: 'includes/SQL/getData.php',
type: 'POST',
dataType: 'html',
success: function(newContent) {
$.each(newContent, function(newContent) {
console.log(newContent);
$('#example').append('<tr><td>' + newContent + '</td></tr>');
})
}
});
});
</script>
<div class="container">
<div class="row">
<div class="col-lg-12 posts-list" style="padding-top: 30px; padding-bottom: 35px">
<table id="example" class="table table-striped table-bordered">
<thead>
<tr>
<th>Word</th>
<th>deff dic</th>
<th>deff simp</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
getdata.php
<?php
include 'connect.php';
$columns = array();
$sql = "SELECT * FROM glossary";
$res = mysqli_query($conn, $sql) or die("Error: ".mysqli_error($conn));
$dataArray = '';
while($row = mysqli_fetch_array($res) ) {
$dataArray .= '<div class="post" id="post_'.$row["id"].'">
<div class="single-post row generic-blockquote" style="background-color: #F1F1F1; margin-bottom: 10px;">
<div class="col-lg-9 col-md-9 ">
<a class="posts-title" href="blog-single.html"><h1>'.$row["Word"].'</h1></a>
<p class="excert">
Accounts help you do money stuff.
</p>
<a href="blog-single.html" class="genric-btn primary">More info</a>
</div>
</div>
</div>
';
}
echo json_encode($dataArray);
错误
Uncaught TypeError: url.indexOf is not a function
at jQuery.fn.init.jQuery.fn.load (jquery-3.3.1.js:9857)
at waypoints.min.js:8
at waypoints.min.js:8
at waypoints.min.js:8
at waypoints.min.js:8
jquery-3.3.1.js:489 Uncaught TypeError: Cannot use 'in' operator to search for 'length' in "<div class=\"post\" id=\"post_1\">\r\n <div class=\"single-post row generic-blockquote\" style=\"background-color: #F1F1F1; margin-bottom: 10px;\">\r\n <div class=\"col-lg-9 col-md-9 \">\r\n <a class=\"posts-title\" href=\"blog-single.html\"><h1>management<\/h1><\/a>\r\n <p class=\"excert\">\r\n Accounts help you do money stuff.\r\n <\/p>\r\n <a href=\"blog-single.html\" class=\"genric-btn primary\">More info<\/a>\r\n <\/div>\r\n <\/div>\r\n <\/div>\r\n <div class=\"post\" id=\"post_2\">\r\n <div class=\"single-post row generic-blockquote\" style=\"background-color: #F1F1F1; margin-bottom: 10px;\">\r\n <div class=\"col-lg-9 col-md-9 \">\r\n <a class=\"posts-title\" href=\"blog-single.html\"><h1>profit<\/h1><\/a>\r\n <p class=\"excert\">\r\n Accounts help you do money stuff.\r\n <\/p>\r\n <a href=\"blog-single.html\" class=\"genric-btn primary\">More info<\/a>\r\n <\/div>\r\n <\/div>\r\n <\/div>\r\n <div class=\"post\" id=\"post_3\">\r\n <div class=\"single-post row generic-blockquote\" style=\"background-color: #F1F1F1; margin-bottom: 10px;\">\r\n <div class=\"col-lg-9 col-md-9 \">\r\n <a class=\"posts-title\" href=\"blog-single.html\"><h1>marketing<\/h1><\/a>\r\n <p class=\"excert\">\r\n Accounts help you do money stuff.\r\n <\/p>\r\n <a href=\"blog-single.html\" class=\"genric-btn primary\">More info<\/a>\r\n <\/div>\r\n <\/div>\r\n <\/div>\r\n "
at isArrayLike (jquery-3.3.1.js:489)
at Function.each (jquery-3.3.1.js:351)
at Object.success (test.php:62)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
【问题讨论】:
-
请尝试将所有需要的代码放在问题本身中,而不是外部。
-
@Dharman 我阅读了这篇文章并尝试修复,但它们对我的问题没有帮助