Ajax query

From: Date: Fri, 08 Sep 2023 23:27:37 +0000
Subject: Ajax query
Groups: php.general 
Request: Send a blank email to php-general+get-328274@lists.php.net to get a copy of this message
Hello. I'm trying to get a "simple" ajax going, but the half-dozen examples I've tried do not work. It Should simply run/activate a PHP script every 5 or 10 seconds, then display the output in the specified DIV. however, when I go to the developer tools, it says there is something wrong with the ajax line (and nothing changes on my screen) Stupid query 1: <link rel="stylesheet" href="/css/font-awesome.min.css" /> Do I need to 'load' Ajax somehow - like Javascript ? I do not see this in ANY examples/tutorials I see. EXAMPLES:- Here are 2 examples I've tried (apparently these are accepted answers to other peoples queries) I did the full https://domain.com/rotatestats.php and /rotatestats.php - still same problem. ONE: <script type="text/javascript"> setInterval(function() { $.ajax( "/rotatestats.php" ).done(function(res) { <<< PROBLEM LINE document.getElementById("rot").innerHTML = res; }) }, 3000); </script> ================= TWO :- <script type="text/javascript"> function updateShouts(){ // Assuming we have #shoutbox $('#rot').load('rotatestats.php'); << PROBLEM LINE } setInterval( "updateShouts()", 10000 ); </script> {/literal} <div id="rot"> NEW: </div> END EXAMPLES ERROR MESSAGE IN DEVELOPER TOOLS: Uncaught ReferenceError: $ is not defined at updateShouts (*WORD*:358:5) at <anonymous>:1:1 The WORD is some HTML output I do previous to the script. its NOT part of the script / div.. apparently it IS refreshing - which is good, but the output isn't appearing Are these two nearly there? I'm not sure what the problem is with the PHP script. if I go to the script directly, it displays a random number.. (Once I get it going, I'll fix up the script to do what I want. Gordon.

« previous php.general (#328274) next »