Current location: Hot Scripts Forums » Other Discussions » Other Topics » AJAX » calling a table through ajax function


calling a table through ajax function

Reply
  #1 (permalink)  
Old 08-26-09, 11:53 PM
raizel's Avatar
raizel raizel is offline
Newbie Coder
 
Join Date: Feb 2009
Location: India
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Question calling a table through ajax function

Hi,
I am calling a page called alert_message.php through function show_alert() in alerts.php
The below one is alerts.php
HTML Code:
<head>
<script type="text/javascript">

var xmlHttp;
function show_alert()

{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="alert_message.php";

alert(url);

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {


document.getElementById("txtHint").innerHTML = 

= xmlHttp.responseText; 

//alert(document.getElementById("txtHint").innerHTML);

}
}

function GetXmlHttpObject()
{
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;
}

</script>
</head>


<form>
<input type="button" value="button"  onclick="show_alert();" style="margin-right:151px;" valign="top" class="button">
<form>
<div id="txtHint"></div>

<?php include("include/footer.php");?>
file name alerts_message.php
PHP Code:



<?php
include("../include/dbconnect.php");
?>
<?php
$sql
="SELECT * FROM alerts where created_by='demo' & status='1'";
 
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width="350" align='middle'>
<tr>
<td width="60">created On </td><td><? echo $rows['date_created']; ?></td>
</tr>
<tr>
<td width="60">Message</td><td><? echo $rows['message']; ?></td>



</tr>
<?}?>
</table>

Can I call this file without button click, If I click on button click nothing comes up.

help me, where I am wrong.

Thanks,


raizel
Reply With Quote
  #2 (permalink)  
Old 08-27-09, 01:19 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Quote:
document.getElementById("txtHint").innerHTML =

= xmlHttp.responseText;
should be:

Code:
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
Reply With Quote
  #3 (permalink)  
Old 08-27-09, 10:55 PM
raizel's Avatar
raizel raizel is offline
Newbie Coder
 
Join Date: Feb 2009
Location: India
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
Hi,

Thank you Wire Hooper . It worked.


Rgds,
Raizel
Reply With Quote
Reply

Bookmarks

« - | - »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL database countll Database 2 06-19-07 04:20 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Problem with a sort table js function tdubyou JavaScript 0 05-03-04 09:19 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 12:34 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.