Ajax query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux