Fetching data with Ajax and ASP, PHP - AJAX Sample Program ~ Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples
Ajax Training, Learn Ajax Video Tutorials Online, Ajax Examples: Fetching data with Ajax and ASP, PHP - AJAX Sample Program

Fetching data with Ajax and ASP, PHP - AJAX Sample Program

// http://localhost/ajax/index3.html
//Fetching data with Ajax and ASP, PHP - AJAX Sample Program

<html>
<head>
<title>Ajax and PHP at work</title>

<script language = "javascript">
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);

XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}

XMLHttpRequestObject.send(null);
}
}
</script>
</head>

<body>

<H1>Fetching data with Ajax and PHP</H1>

<form>
<input type = "button" value = "Display Message"
onclick = "getData('data.php', 'targetDiv')">
</form>

<div id="targetDiv">
<p>The fetched data will go here.</p>
</div>

</body>
</html>

//data.php

<?php
echo 'This text was fetched using Ajax.';
?>

//data.asp

<%
Response.write("This text was fetched using Ajax.")
%>

Related Posts by Categories

0 comments:

Useful Links on Adobe Flex

Your Ad Here

Latest Books on Adobe Flex