adamjones Posted July 22, 2010 Share Posted July 22, 2010 Hi, I have this script which runs my 'notifications.php' file every 5 seconds to display new notifications to the user. <script type="text/javascript"> jQuery(document).ready(function($) { setInterval(function (){$('#date').load('notifications.php');}, 5000); })(jQuery); </script> Notifications.php; <script type="text/javascript"> if (!window.console || !console.firebug) { var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; window.console = {}; for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {}; } (function($){ $(document).ready(function(){ // This value can be true, false or a function to be used as a callback when the closer is clciked $.jGrowl.defaults.closer = function() { console.log("Closing everything!", this); }; // A callback for logging notifications. $.jGrowl.defaults.log = function(e,m,o) { $('#logs').append("<div><strong>#" + $(e).attr('id') + "</strong> <em>" + (new Date()).getTime() + "</em>: " + m + " (" + o.theme + ")</div>") } <?php require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $sql="SELECT * FROM alerts WHERE username='".$_SESSION['username']."'"; $result=mysql_query($sql); while ($rows = mysql_fetch_assoc($result)){ echo "".$rows['alert'].""; } $sql2="DELETE FROM alerts WHERE username='".$_SESSION['username']."'"; $result2 = @mysql_query($sql2); ?> }); })(jQuery); </script> However, It just loads a blank page... Thank's. Quote Link to comment Share on other sites More sharing options...
DaiLaughing Posted July 22, 2010 Share Posted July 22, 2010 I can't really understand why you are doing what you are doing so I'm probably not going to be much help but no one else has replied so... Have you tried just putting echo "Hi"; in notifications.php to see if that works? Then add in just the PHP and see if that gives you anything? Then add other stuff in (I don't pretend to understand your Javascript as it's not really my thing). Personally I would have done this with AJAX and written the notifications to an existing HTML element on the page. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 22, 2010 Share Posted July 22, 2010 1) Is there a session_start() in your config.php? The code you showed does not start a session but references $_SESSION variables. This would result in the query returning zero rows and therefore, no output. 2) turn on error_reporting and display_errors (PHP) so you can see any errors that are being reported (including the reference to non-existant session variables) then fix those errors. 3) if you request notifications.php directly from the browser, do you get anything? Note: you may need to look at "View Source" to see what is actually returned. Note: I have never used jQuery, so I can't really say whether that code has problems or not. However, if I understand what it is supposed to do, I think it is a pretty interesting approach. Good Luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.