Ajex Is Easy

A lot of people don’t know the basics of ajex : or passing vars from a page and using JavaScript to call another asp/php/asp.net/javascript page … I f you know php or asp or asp.net and JavaScript event handlers then my friend you are ready to start making use of simple then more advanced Ajax like web interfaces … lts here is a fun simple example :

the “magic” takes place with the JavaScript  XMLHttpRequest()

Put this in the head section of a html / php page

<head>
<title>Some Document </title>
<script type="text/javascript">
function loadXMLDoc(int)
{
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
 {
 document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
 }
 }
xmlhttp.open("GET","result.php?var="+int,true);
xmlhttp.send();
}
function changecolour(){
document.getElementById("change").style.color="red"
}
</script>
</head>
that gets it going note it will call a php page called result.php with a url encode ?var= the javascript var 

 <div id="myDiv"><h2>Let AJAX see if you type hello</h2>
<br />

 <input type="text"  onblur="loadXMLDoc(this.value)"/>
 </div>
(note just type hello) then make a new page called
result.php... and in it put this in it
<?php
$thevar = $_GET['var'];
echo $_GET['var'];
if($_GET['var'] =="hello"){
// could be password validation or what ever
echo "You Typed hello You Are Cool";
$x=1;
}else{
echo"<br/>
<input type='text' value='".$thevar."' style='color:#FF0000'  onblur='loadXMLDoc(this.value)'/> \n";
echo" <br/>Not valid please try again just type `Hello` ";
}
?>
there you go job done you can do any thing in that result page
download example here and have fun 

once you have this idea you can easily see how you can use
(real)  xml to communicate between many applications

Allot of people don’t know the basics of ajex : or passing vars from a page and using JavaScript to call another asp/php/asp.net/javascript  page …

I f you know php or asp or asp.net and JavaScript event handlers then my friend you are ready to start making use of simple then more advanced Ajax like web interfaces … lts here is a fun simple example :

the “magic” takes place with the XMLHttpRequest()

Comments are closed.

Subscription

Fill out the form below to signup to my newsletter and You Can Get New Cool free Scripts , advice ...ect

Our strict privacy policy keeps your email address 100% safe & secure.



























Ads1

Payment Online?
PayPal Merchant Account
Simple Secured Payments
www.PayPal.com/GetPaid





Godaddy Domain Name
Save Money On Domain Names
20% Of Domain Name Special!
www.Godady.com.au





Cheap Web Hosting
Web Hosting Supported by Experts.
3.95$ Hosting. FREE Domain!
justhostrus.com/FreeDomain





Affiliate Tracking
Affiliate Tracking Software
Software Solutions for Every business
www.idevtracking.com





Cool Twitter Automation
The Best thing to happen
To Twitter EVER Free Ac!
www.tweetitlater.org





Designed by Taggart Jensen .