satwant,Thanks to ur response,
I don't know the ajax programming
please give me the code how to run on the windows.
First: whenever U encounter New Development Words always try to Google them and learn them. Because U will Learn them only once and they will help you lifetime
Instead writing ajax,can we use php ?
Not directly with php but with html ,u can do this By Setting Meta Page refresh in Head section of your html page
Following code will make a page to refresh after 5 seconds
<html>
<head>
<meta http-equiv="refresh" content="5" /> </head></html>
- <html>
- <head>
- <meta http-equiv="refresh" content="5" /> </head></html>
if yes please give me the code,its urgent
I make a very simple example to Show this simple concept. Before u implement This please Try to understand usage of functions
Here is Javascript And Html Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Random Country Select By Satwant Hundal</title>
<script type="text/javascript">
/* By: Satwant Hundal
Script : Usage of Set Interval For Ajax Calls
*/
//This is Function to call Over Certain Interval
var i_am_Function=function()
{
// following code is used to initiate Ajax call Object Called XMLHTTPOBJECT
xmlhttp="";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//Function to Handle Data Send By Php Code from Server
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//code to update Your Html Page
var x=document.getElementById('country_name');
x.innerHTML='Ramdom Country:'+xmlhttp.responseText;
}
};
xmlhttp.open("GET",'data.php',true);
xmlhttp.send();
}
window.onload=function(e)
{
// Seeting Up Set Interval Function to 5000 millisecond which means 5 seconds
//for Hour you need to put 3600000
i_am_Function();
var TimeOutId=setInterval(i_am_Function, 5000);
// Time Out ID is Used to Identify Particular Set Interval. Use this to Clear it when u dont
//need it.
//clearInterval(TimeOutId);
}
</script>
<style type="text/css">
#country_name
{
width: 100%; height: 100%; font-size: 80px;
}
</style>
</head>
<body>
<!-- This is Place which is Updated By Above Code -->
<div id="country_name"></div>
</body>
</html>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <title>Random Country Select By Satwant Hundal</title>
- <script type="text/javascript">
- /* By: Satwant Hundal
- Script : Usage of Set Interval For Ajax Calls
- */
- //This is Function to call Over Certain Interval
- var i_am_Function=function()
- {
- // following code is used to initiate Ajax call Object Called XMLHTTPOBJECT
- xmlhttp="";
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- //Function to Handle Data Send By Php Code from Server
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- //code to update Your Html Page
- var x=document.getElementById('country_name');
- x.innerHTML='Ramdom Country:'+xmlhttp.responseText;
- }
-
- };
- xmlhttp.open("GET",'data.php',true);
- xmlhttp.send();
- }
- window.onload=function(e)
- {
- // Seeting Up Set Interval Function to 5000 millisecond which means 5 seconds
- //for Hour you need to put 3600000
- i_am_Function();
- var TimeOutId=setInterval(i_am_Function, 5000);
- // Time Out ID is Used to Identify Particular Set Interval. Use this to Clear it when u dont
- //need it.
- //clearInterval(TimeOutId);
- }
- </script>
- <style type="text/css">
- #country_name
- {
- width: 100%; height: 100%; font-size: 80px;
- }
- </style>
- </head>
- <body>
- <!-- This is Place which is Updated By Above Code -->
- <div id="country_name"></div>
- </body>
- </html>
This Code is Stored in server in a Php File
// Your Connection String Replace UserName and Password
$con = mysql_connect("localhost","YOUR USER NAME","YOUR PASSWORD") or die("Error: ".mysql_error());
//Your DATABASE NAME where country table is stored
mysql_select_db('ssb',$con) or die("Error: ".mysql_error());
$sql="SELECT * FROM `country` ORDER BY RAND() LIMIT 0,1";
$record=mysql_query($sql,$con) or die("Error: ".mysql_error());
$row=mysql_fetch_row($record);
print_r($row[1]);
mysql_close($con) or die("Error: ".mysql_error());
- // Your Connection String Replace UserName and Password
- $con = mysql_connect("localhost","YOUR USER NAME","YOUR PASSWORD") or die("Error: ".mysql_error());
- //Your DATABASE NAME where country table is stored
- mysql_select_db('ssb',$con) or die("Error: ".mysql_error());
- $sql="SELECT * FROM `country` ORDER BY RAND() LIMIT 0,1";
- $record=mysql_query($sql,$con) or die("Error: ".mysql_error());
- $row=mysql_fetch_row($record);
- print_r($row[1]);
- mysql_close($con) or die("Error: ".mysql_error());
You can download Full example from My Site
http://satwant(.)tk/publicDownload/CountryExample.zip