2012-05-06 15 views
0
$.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) 
     } 
    }) 

の「date_notify」私が持っているこのエラーをプロパティを読み取ることができません。 10の結果を持ってほしい...私のSQL部分では私はLIMITクエリしませんでした。ここに私の質問javascriptをキャッチされない例外TypeErrorは:Chromeで未定義

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 

これを変更する方法はありますか?

答えて

1

使用しANDはあなたのループ内で条件付き編:

for(var i=0; i<responseJSON.length && i<10; i++) 

この方法でループが早い方、ときiいずれかのエントリ数を超えるか、10に達するカットします。エントリ数が10未満の場合、最初の条件は最初にfalseになり、10を超えるレコードがある場合は、2番目の条件が最初にfalseになります。

+0

これは素晴らしいです!おかげで兄はそれを知らなかった –

1

SQLクエリを制限します。データが機密扱いである場合、潜在的なセキュリティ上の問題は何も言わずに、使用しないデータに対してネットワーク帯域幅とサーバーリソースを消費する理由はありません。

関連する問題