$.ajax({
url: "notifications.php",
dataType: "json",
success: function(responseJSON) {
if (responseJSON.length > 0) {
document.title = document.title.replace(/^(?:\(\d+\))?/, "(" + responseJSON.length + ") ")
for (var i=0; i<10; i++) {
console.log(responseJSON[i].date_notify')
}
}
}, error : function(x) {
console.log(x.responseText)
}
})
在Chrome“date_notify”我有这样的错误:的JavaScript遗漏的类型错误:无法读取属性未定义
Uncaught TypeError: Cannot read property 'date_notify' of undefined
而且我在这部分想通了for (var i=0; i<10; i++)
应更换到for (var i=0; i<responseJSON.length; i++)
问题是只有我想要有10个结果...在我的sql部分我没有LIMIT的查询。这是我的查询
SELECT users.lastname, users.firstname, users.screenname, notifications.notify_id,
notifications.tagged_by, notifications.user_id, notifications.post_id,
notifications.type, notifications.action, notifications.date_notify,
notifications.notify_id
FROM website.users users INNER JOIN website.notifications notifications
ON (users.user_id = notifications.user_id)
WHERE notifications.user_id = ? and notifications.action = ?
ORDER BY notifications.notify_id DESC
//LIMIT 10
有什么可能的方法来改变这个吗?
这太好了!感谢兄弟不知道这一点 –