Får inte exemplet att fungera och förstår inte varför. Jag är helt ny med det här så kan ha missat nåt fundamentalt. Koden nedan:
<?php // Error Handling ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
// BACKEND
if( isset($_GET['ajax']) ) {
echo date('l dS \of F Y h:i:s A');
exit(); } ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title>Scheduled ajax Example</title>
<script type="text/javascript" src="/yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="/yui/build/connection/connection-min.js"></script>
<script type="text/javascript">
// My namespace (to avoid conflicts with global variables)
FOTI = window.FOTI ¦¦ {};
// My page specific object
FOTI.ScheduledajaxExample = function() { return {
/** * (psuedo) Private method for connecting. */
_connect : function(method,uri,callback,postdata){
YAHOO.util.Connect.asyncRequest(method,uri,callback,postdata);
},
/** * Node used to store the results
*/ resultsNode : null, /** * A counter, just for testing */ counter : 0, /** * Initialization method */ init : function(e) {
// Get the results node
FOTI.ScheduledajaxExample.resultsNode = YAHOO.util.Dom.get('results');
if( FOTI.ScheduledajaxExample.resultsNode!= null ) {
// Start the schedule
setTimeout( FOTI.ScheduledajaxExample.connect, 3000 ); } },
/** * Connect to server */
connect : function() {
// ajax connection stuff goes here
var uri = 'scheduledajax.php?ajax=true&nocache=' + (new Date()).getTime();
var timeout = 2; // seconds
var callback = { success : function(o){
FOTI.ScheduledajaxExample.resultsNode.innerHTML = "<div>" + (FOTI.ScheduledajaxExample.counter++) + " : " + o.responseText + "</div>";
setTimeout( FOTI.ScheduledajaxExample.connect, 3000 ); },
failure : function(){
alert('Connection failed'); }, timeout : timeout * 1000 }; FOTI.ScheduledajaxExample._connect('GET', uri, callback, null ); } }; }();
// Fire my methods once the page loads
YAHOO.util.Event.on(window,'load',FOTI.ScheduledajaxExample.init);
</script>
</head>
<body>
<div id="results"> When the update occurs, the results will be listed here. </div>
</body>
</html>
Har inkluderat hela yui-paketet!