【发布时间】:2012-01-18 20:48:22
【问题描述】:
我正在尝试加载下一组数据,然后在 ajax 调用后删除数据。但我只让ajax工作一次。点击“获取更多报价”后,没有任何反应。
网站:http://kdevs.site40.net/#more(点击获取更多报价)
阿贾克斯:
function getQuotes(start, limit) {
//Clear the recent list element
$(".recent-list").html("");
$.ajax({
url: "quotes.php?start=" + start + "&limit=" + limit,
success: function (data) {
ata = jQuery.parseJSON(data);
console.log("success");
//Data should now be a javascript array of objects.
for (i = 0; i < data.length; i++) {
var newElem = jQuery("<li></li>").attr('id', data[i].id).addClass('quote-wrap-group');
newElem.append("<div class='quote'><p>" + data[i].quote + "</p></div>");
$(".recent-list").append(newElem);
}
}
});
}
$("#more").click(function () {
var currentIndex = 0;
getQuotes(currentIndex = currentIndex + 10, 10);
currentIndex += 10;
});
PHP 返回 json:
<?php
require("inc/connect.php");
$start = $_GET['start'];
$limit = $_GET['limit'];
$sql = "SELECT * FROM entries ORDER BY id DESC LIMIT ".$start.", ".$limit;
$result = mysql_query($sql, $link) or die("Error in query: ".mysql_error());
$data = array();
while($row = mysql_fetch_array($result)) {
array_push($data, $row);
}
echo(json_encode($data));
?>
我知道这不是 PHP,因为:http://kdevs.site40.net/quotes.php?start=0&limit=10 有效。
我做错了什么?
【问题讨论】:
-
您的查询受到 SQL 注入的影响。阅读en.wikipedia.org/wiki/SQL_injection,然后修复它。
-
^ 我知道。如果我将它发送给客户,我会先解决这个问题......
标签: php javascript jquery ajax