The error means that you are trying to use jQuery when it is not loaded.
Did you include the js include for jquery? If so then you want to wait until it is done before executing it:
$(window).load(function(){
//your code here
});
On Fri, Sep 8, 2023 at 8:19 PM JEFFRY KILLEN <jekillen@xxxxxxxxxxx> wrote:
You do not need to "load" ajax. The object is built into _javascript_. But there a newer versions
that the xmlHttpRequestObject.
In general, your ajax request must be initiated by a user event such as mouse click or a keydown
event. So that has to be written in. Also there is a sequence for intiating the ajax request that must
be adhered to. THEN, on the server side there has to be PHP or other serverside code to recognize
and handle the request and return a response if there should be one. The last phase if there is a
response expected is for _javascript_ to handle the response.
Mostly, the ajax request is done ASYNCRONISTICALLY. That just means that a response will NOT
cause the browser window to reload. So state can be maintained. In technical terms it means that
the request is done outside of the browsers main thread.
A page initiating the request can process its response. But that is tricky to program.
It essentially means that the PHP that process the request must exist above the
DTD declaration and 'exit' as soon as it completes the request. It must also call
header() and issue a header indicating the type of response: text, json, whatever.
Then it uses print or echo to sent the response body. Then exit must called to prevent
any html from being generated.
1 header()
2 print (or echo) response body
3 exit
The newer version of asyncronous requests is more difficult and less intuitive.
Here is the result of a Google search for _javascript_ training.
https://www.google.com/search?client=firefox-b-1-d&q=_javascript_+training
Here is another for mozilla _javascript_:
https://www.google.com/search?q=mozilla+_javascript_&client=firefox-b-1-d&sca_esv=563870670&ei=T7X7ZOWYCa-n0PEPr-eMwAg&oq=mozilla&gs_lp=Egxnd3Mtd2l6LXNlcnAiB21vemlsbGEqAggAMggQABiKBRiRAjITEC4YigUYsQMYgwEYxwEY0QMYQzINEAAYigUYsQMYgwEYQzILEAAYigUYsQMYkQIyDRAAGIoFGLEDGIMBGEMyExAuGIoFGLEDGIMBGMcBGNEDGEMyCBAAGIoFGJECMggQABiKBRiRAjIHEAAYigUYQzIEEAAYA0iZ6RxQ0ZAcWKDVHHACeAKQAQCYAYgBoAH4D6oBBDIzLjK4AQHIAQD4AQGoAgrCAgoQABhHGNYEGLADwgIKEAAYigUYsAMYQ8ICDhAAGOQCGNYEGLAD2AEBwgIWEC4YigUYxwEY0QMYyAMYsAMYQ9gBAsICBBAAGEfCAgUQABiABMICCBAAGIAEGLEDwgILEAAYgAQYsQMYgwHCAgcQLhiKBRhDwgILEC4YgAQYsQMYgwHCAgsQLhiKBRixAxiDAcICFhAuGAMYjwEY5QIY6gIYtAIYjAPYAQPCAhYQABgDGI8BGOUCGOoCGLQCGIwD2AEDwgILEAAYigUYsQMYgwHCAg4QLhiABBixAxjHARjRA8ICERAuGIAEGLEDGIMBGMcBGNEDwgIFEC4YgATCAggQLhiABBixA8ICCxAuGIAEGMcBGNEDwgINEC4YigUYxwEY0QMYQ8ICCBAuGLEDGIAE4gMEGAAgQYgGAZAGCLoGBggBEAEYCboGBggCEAEYCLoGBAgDGAo&sclient=gws-wiz-serp
_javascript_ ajax:
https://www.google.com/search?q=_javascript_+ajax&client=firefox-b-1-d&sca_esv=563870670&ei=8rj7ZODYHY7G0PEP7JiYyAI&oq=_javascript_+ajax&gs_lp=Egxnd3Mtd2l6LXNlcnAiD2phdmFzY3JpcHQgYWpheCoCCAAyCBAAGIoFGJECMggQABiKBRiRAjIFEAAYgAQyBRAAGIAEMgUQABiABDIFEAAYgAQyBRAAGIAEMgUQABiABDIFEAAYgAQyBRAAGIAESKmVBVD5pARY9-sEcAh4AZABAJgBcaAB5AmqAQQxNS4xuAEByAEA-AEBwgIKEAAYRxjWBBiwA8ICChAAGIoFGLADGEPCAg4QABjkAhjWBBiwA9gBAcICGRAuGIoFGMcBGNEDGNQCGMgDGLADGEPYAQLCAhAQLhiKBRjIAxiwAxhD2AECwgIHEAAYDRiABMICBhAAGAcYHsICExAAGA0YgAQYsQMYgwEYsQMYgwHCAg0QABgNGIAEGLEDGIMBwgIKEAAYDRiABBixA8ICDRAAGIoFGA0YsQMYgwHCAgcQABiKBRhDwgINEAAYigUYsQMYgwEYQ8ICChAAGIoFGLEDGEPCAgsQABiABBixAxiDAcICDhAAGIoFGLEDGIMBGJECwgILEAAYigUYsQMYkQLCAggQABiABBixA8ICBxAAGIAEGArCAg0QABgWGB4YDxjxBBgKwgIIEAAYigUYhgPiAwQYACBBiAYBkAYRugYGCAEQARgJugYGCAIQARgI&sclient=gws-wiz-serp
> On Sep 8, 2023, at 4:27 PM, gordonisnz@xxxxxxxxx wrote:
>
> 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="" />
>
> 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.