My favorites | Sign in
Project Hosting will be READ-ONLY Thursday at 3:00pm UTC for up to 3 hours for network maintenance.
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
if ($_REQUEST['ask'] == '') {

# This first part is where we send out a HTML page which the client will use to
# make requests. The requests will come back to this same PHP page, but the 'ask'
# part of the REQUEST won't be empty this time, so then we move on to the next
# part where we send back a cheery little text string with the time. The Javascript
# embedded in the HTML page will accept that string and stick it into the html div
# whose identifier is "result".

?>
<HTML>
<head>
<title>AJAX with PHP & Javascript</title>
</head>
<body>
Silly little AJAX demo
<table>
<tr><td bgcolor="lightblue">
<button type="button" onclick="onclickfunc();">Click</button> to send a request
to the server
</td></tr>
<tr><td bgcolor="yellow">
<div id="result">Empty so far</div>
</td></tr>
</table>
</body>
<script type="text/javascript">
// The browser might cache the results of HTTP requests, so we need an incrementing
// count to make sure each URL is unique enough to really fire off a new request.
var count = 0;
function onclickfunc()
{
var xmlhttp;
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Your browser does not support XMLHTTP!");
}
// Handler for the server's response
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
document.getElementById('result').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "blarg.php?ask=foo&count=" + count, true);
count++;
xmlhttp.send(null);
}
</script>
</HTML>

<?php
} else {

# Here's our happy little response to the AJAX request, where we send back a little
# string with the time. We could put anything in here. In many cases people send back
# XML at this point, but plain text works as well.

?>
Yummy AJAX stuff from the server at
<?php
echo date('M, d Y (H:i:s)');
}
?>

Change log

r35 by will.ware on Aug 27, 2009   Diff
Doh! typos...
Go to: 
Project members, sign in to write a code review

Older revisions

r34 by will.ware on Aug 27, 2009   Diff
Fix some broken javascript.

r33 by will.ware on Aug 25, 2009   Diff
Here is some very simple ajax stuff.
All revisions of this file

File info

Size: 2359 bytes, 69 lines
Powered by Google Project Hosting