Ayoub Sbai Ayoub Sbai - 2 months ago 11
Ajax Question

notifications don't show up using jquery ajax get

i want to display the notifications on a page, so i used window.setinterval function that contains an AJAX get method !

header.asp



window.setInterval(function() {
$.ajax({
url: 'getnotifications.asp',
type: 'GET',
dataType: 'javascript',
cache: false,
success: function(data) {
return data;
}
});
}, 10000);





getnotifications.asp



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset="UTF-8" %>
<!--#INCLUDE file="connect/site_conn.asp" -->
<!--#INCLUDE file="connect/members_conn.asp" -->
<!--#INCLUDE file="connect/notifications_conn.asp" -->
<!--#INCLUDE file="global.asp" -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.growl.js" type="text/javascript"></script>
<link href="css/jquery.growl.css" rel="stylesheet" type="text/css" />
<%
Dim rsGetLatestNotifications
Set rsGetLatestNotifications = Server.CreateObject("ADODB.Recordset")
strSQLData = "SELECT * FROM TB_NOTIFICATIONS WHERE NOT_TO = " & mem_id & " AND NOT_READ = false"
strSQLData = "" & strSQLData & ";"
rsGetLatestNotifications.CursorType = 2
rsGetLatestNotifications.LockType = 3
rsGetLatestNotifications.Open strSQLData, adoConNotificationsData

Do While not rsGetLatestNotifications.EOF %>
<script>
$( window ).load(function() {
$.growl.notice({ message: "The kitten is cute! hahaha" });
});
</script>
<%
rsGetLatestNotifications.MoveNext
Loop

rsGetLatestNotifications.Close
Set rsGetLatestNotifications = Nothing

adoConNotificationsData.Close
Set adoConNotificationsData = Nothing
adoConSiteData.Close
Set adoConSiteData = Nothing
adoConMemData.Close
Set adoConMemData = Nothing
%>





the code doesn't work and i know something is missing ! pls i'll be grateful if you help me

Answer
<% Dim member Set JSONdata= jsObject()
Do While not rsGetLatestNotifications.EOF %>
   JSONdata("message") = "The kitten is cute! hahaha"
   rsGetLatestNotifications.MoveNext
Loop
JSONdata.Flush
%>

window.setInterval(function() {
$.ajax({
    url: 'getnotifications.asp',
    type: 'GET',
    dataType: 'json',
    cache: false,
    success: function(JSONdata) {
         $.growl.notice(JSONdata);
    }
});
}, 10000);