Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ajax/js/php

Featured Replies

Hello, Ive spent hours now trying to find a solution to this but no luck (n)

 

anyway i need a php file to run every couple of seconds to update the amount of messages that are in there inbox

 

i have my main php file which contains the main structure of the page/layout etc

 

in the head of that document ive got

<script type="text/javascript">

function loadcont() {

$("#count").load("includes/msgcount.php");

var t=setTimeout("loadcont()",4000);

}

</script>

 

and in the body i have a div with the id called count

the javascript is initially being ran by <body onload="loadcont()">

 

and that parts working fine, the php file echos once into the file like its supposed to and then if i update the msgcount.php file and wait on the website for the page to refresh the info it doesnt, baring in mind the setTimeout is definatly working as i tested it with an alert()

 

So in short words, is this possible?

 

Thanks

Hello, Ive spent hours now trying to find a solution to this but no luck (n)

 

anyway i need a php file to run every couple of seconds to update the amount of messages that are in there inbox

 

i have my main php file which contains the main structure of the page/layout etc

 

in the head of that document ive got

<script type="text/javascript">

function loadcont() {

$("#count").load("includes/msgcount.php");

var t=setTimeout("loadcont()",4000);

}

</script>

 

and in the body i have a div with the id called count

the javascript is initially being ran by <body onload="loadcont()">

 

and that parts working fine, the php file echos once into the file like its supposed to and then if i update the msgcount.php file and wait on the website for the page to refresh the info it doesnt, baring in mind the setTimeout is definatly working as i tested it with an alert()

 

So in short words, is this possible?

 

Thanks

 

Yeah, that should work fine.

 

If it's not updating then I guess it must be a problem with your msgcount.php file. Can you post the code for it?

  • Author

Yeah, that should work fine.

 

If it's not updating then I guess it must be a problem with your msgcount.php file. Can you post the code for it?

 

<?php
require_once("config.php");
//require_once("functions.php");
//logincheck();

$cid = $_SESSION['id'];

$sqlquery = "SELECT * FROM `messages` WHERE (uid2 = '$cid' AND read1 = '0')";
$result = mysql_query($sqlquery)or die(mysql_error());
$unreadmsgs = mysql_num_rows($result); //to get the total rows

echo $unreadmsgs;
?>

 

thats the msgcount.php code, if i run the msgcount.php script on its own it works though and updates accordingly

Edited by web-itec

  • Author

Edit* the reason it didnt work is because the session must have ended for some reason and it wasnt getting the id to get the messages, so msgcount.php does work but the loading of it through javascript doesnt

 

 

2nd EDIT** it works now, just so you know what went wrong, it was because i didnt import the latest jq

 

<script src="http://code.jquery.com/jquery-latest.js"></script>

Edited by web-itec

Instead of recursively calling the function with a setTimeout delay, simply use this:

 

<script type="text/javascript">
window.onload = function(){
   setInterval(loadcont, 4000);
};
</script>

 

Or the equivalent jQuery...

 

<script type="text/javascript">
$(document).ready(function(){
   setInterval(loadcont, 4000);
});
</script>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.