Try this example:
------------------------------
First File: save as index.html
------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> OnKeyUp </TITLE>
<script type="text/javascript" src="ajax.js"> </script>
</HEAD>
<BODY>
Type here :
<input type="text" onkeyup="reload('refresh.php','text='+this.value,'display')">
<br>
<br> Response: <br>
<span id="display"></span>
</BODY>
</HTML>
---------------------------------
Second File: save as refresh.php
---------------------------------
<?
echo $_REQUEST['text'];
?>
---------------------------------
Third File: save as ajax.js
---------------------------------
function createRequestObject(){
var request_;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_ = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_ = new XMLHttpRequest();
}
return request_;
}
var http = createRequestObject();
function reload(page,param,refreshlocation) {
http.open('get', page+'?'+param);
http.onreadystatechange = function(){
if (http.readyState == 4) {
var response = http.responseText;
document.getElementById(refreshlocation).innerHTML = response;
}else {
document.getElementById(refreshlocation).innerHTML = "Loading...";
}
}
http.send(null);
}
Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts
Ajax response sample
Labels:
Ajax
How Ajax works with my php code?
Ajax amused me! With this technique my life makes it easier than before. I just read how this Ajax works until i finally created one that fits my needs, and i want to share it.
Here is what you need to have:
--------------------------------
Here is what you need to have:
--------------------------------
function createRequestObject(){
var request_;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_ = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_ = new XMLHttpRequest();
}
return request_;
}
var http = createRequestObject();
function reload(page,param,refreshlocation) {
http.open('get', page+'?'+param);
http.onreadystatechange = function(){
if (http.readyState == 4)
{
var response = http.responseText;
document.getElementById(refreshlocation).innerHTML = response;
}else {
document.getElementById(refreshlocation).innerHTML = "";Loading...
}
}
http.send(null);
}
Labels:
Ajax
Subscribe to:
Posts (Atom)
Loading...