$.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
有什麼可能的方法來改變這個嗎?
這太好了!感謝兄弟不知道這一點 –