SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 41 | Next

Thomas Powell

"Ajax: The Complete Reference"

php
program shown here.
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Type: text/xml");
$ip = $_SERVER['REMOTE_ADDR'];
$msg = "Hello World to user from " . $ip . " at ". date("h:i:s A");
print "";
print "$msg";
?>
Ajax does not favor or require any particular server-side language or framework. The
general idea should be the same in whatever environment you are comfortable. For
example, sayhello.jsp looks quite similar to the PHP version.
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setContentType("text/xml");
String ip = request.getRemoteAddr();
String msg = "Hello World to user from " + ip + " at " + new java.text
.SimpleDateFormat("h:m:s a").format(new java.util.Date());
out.println("");
out.print("" + msg + "");
%>
NOTE PHP is used in most examples, given its simplicity and readability, but any server-side
technology, such as Ruby, ASP.NET, and Java, is more than capable of servicing Ajax requests.
On the server-side, we first emit some HTTP headers to indicate that the result should
not be cached. Mixing Ajax and caching can be quite troubling and addressing it properly is
a significant topic of Chapter 6.


Pages:
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