String :
MD5 :
As requested, this article will show you how to create a simple AJAX Application. Before you start, you may test the AJAX Example above
- md5.html
- processor.js
- getmd5.php
1. md5.html
Is the AJAX Example interface html file.
<html>
<head>
<script src=”processor.js”></script> <!– imports the AJAX script –>
</head>
<body>
<form>
String :
<input type=”text” id=”txt1″
onkeyup=”showHint(this.value)” size=”27″ <!– call the function on the AJAX script –>
maxlength=”32″>
</form>
<p>MD5 : <b><span id=”txtMd5″></span></b></p> <!– show the result –>
</body>
</html>
2. processor.js
This is file stores AJAX script, and sends information to getmd5.php through $_GET request.
var xmlHttp;
function showHint(str) // sends the calculated MD5 Value to the form
{
if (str.length==0)
{
document.getElementById(“txtMd5″).innerHTML=”";
return;
}
xmlHttp=GetXmlHttpObject(); //define xmlHTTP type
if (xmlHttp==null)
{
alert (“Your browser does not support AJAX!”);
return;
}
var url=”http://zoiz.web.id/getmd5.php”; // PHP Script URL that will calculate MD5
url=url+”?q=”+str; // Send value through GET
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4) //check if the request is completed
{
document.getElementById(“txtMd5″).innerHTML=xmlHttp.responseText; // assign the value
}
}
function GetXmlHttpObject(); // catch your browser type and assign xmlHttp value
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}
3. getmd5.php
Calculate MD5 from the string it recieves.
<?
$txtMd5=$_GET['q'];
if(strlen($txtMd5)>=33){ // make sure that the string not longer than 32 char
echo “Ups”; // display error
}
else
{
echo md5($txtMd5); // Provide the MD5 hash
}
?>
Jobs done, simple and easy isn’t it?
Any comment and feedback is welcomed (anyway I am not a pro Coder, correct me if I am wrong in this article
).
Reference :




Nice.
Btw, you might want to glue up the onkeyup event some timeout delay before every key press would eventually call some XHR request. Like typing “testing” chars would brings up 7 XHR calls which isn’t necessarily needed as the the final output would just need one XHR call.
My 2 cents.
thanks, that’s a nice idea
ok, Zoiz. nice to know you. I has put your site address in my blogroll. It’s ok if you put my site address. Thanks
hehe.. Ok, i’ve also added your blog to my blogroll
ew, i thought it talk `bout a soccer team, >,<
I think I fall in love with AJAX.
Thanks.
.::Astalavista::.
hi…
i want to ask s’thing…
hehe…
i want to build a ‘md5 encryption’ page like http://zoiz.web.id/ajaxify-md5-encryption
but my homepage is error… http://m1nd.th0r.info/?page_id=43
i already install the plugin, but i don’t know how to use it…
may you teach me??
i’m only a newbie…
my e-mail: raymond.tenggario@gmail.com
hehehe…
Thankz for all….:)
You miss this one M1nD,
remove the /
can you send me that’s script and teach me how to install it….thank’s
You only need three files, and all of the source codes are there
copy and save them in separate file and execute he md5.html in your browser
I am sure it’ll work Sizuki^^
Thankz,bro….
but….
gw bnr2 g ngerti slhnya dmn….
plz help me….
Tq yach…;)
its really fantasic:)