Ajax is revolusioner method in building web application, it’s used javascript XMLHttpRequest object to communicate with server without have to reloading the page.
I am new to Ajax, this is my “hello world” application to show how using Ajax with Java.
(ajaxHello.jsp)
view plaincopy to clipboardprint
1. <html>
2.
3. <head>
4.
5. <title>Hello Ajax</title>
6.
7. </head>
8.
9. <body>
10.
11. <script type="text/javascript">
12.
13. function ajaxFunction()
14.
15. {
16.
17. var xmlHttp;
18.
19. try
20. {
21. // Firefox, Opera 8.0+, Safari
22. xmlHttp=new XMLHttpRequest();
23. }
24. catch (e)
25. {
26. // Internet Explorer
27. try
28. {
29. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
30. }
31. catch (e)
32. {
33. try
34. {
35. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
36. }
37. catch (e)
38. {
39. alert("Your browser does not support AJAX!");
40. return false;
41. }
42. }
43. }
44. xmlHttp.onreadystatechange=function()
45. {
46. if(xmlHttp.readyState==4)
47. {
48. document.getElementById("timeInfo").innerHTML=xmlHttp.responseText;
49. }
50. }
51. xmlHttp.open("GET","time.jsp",true);
52. xmlHttp.send(null);
53. }
54. </script>
55. <form name="aForm">
56. Name: <input type="text" name="username" onkeyup="ajaxFunction();" />
57. Hi, you are typing the text at
58. <span id="timeInfo" STYLE="font-family: sans-serif; color: red; font-size: 12pt"></span>
59. </form>
60. </body>
61. </html>
<html>
<head>
<title>Hello Ajax</title>
</head>
<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("timeInfo").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.jsp",true);
xmlHttp.send(null);
}
</script>
<form name="aForm">
Name: <input type="text" name="username" onkeyup="ajaxFunction();" />
Hi, you are typing the text at
<span id="timeInfo" STYLE="font-family: sans-serif; color: red; font-size: 12pt"></span>
</form>
</body>
</html>
(time.jsp)
view plaincopy to clipboardprint
1. <strong><%= new java.text.SimpleDateFormat("dd MMM yyyy, hh:mm:ss").format( new java.util.Date() ) %>
2. </strong>
source: gardiary.wordpress
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.
Be the first ... |Add your comment.
Your Comment ...
Name (required)
Email (required, hidden)
Website
