...

View Full Version : HELP - Script not working...



shedokan
11-13-2007, 10:56 PM
here is the script:

<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
window.onload=function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
requestNews = ajaxRequest;
requestNews.onreadystatechange = function(){
if(requestNews.readyState == 4){
var newsDisplay = document.getElementById("news");
newsDisplay.innerHTML = requestNews.responseText;
}
}
requestNews.open("GET", "news.php", true);
requestNews.send(null);
}
//-->
</script>
here is the page:

<!-- here is the header style of the page-->
<center>
<div style="border:1px solid black;background-color:#DDDD00;width:95%;padding:2px;" align="right">
.ברוכים הבאים לניאוסטאר, כאן תוכלו למצוא את כל העזרה שאתם צריכים בניאופטס
</div>
<br>
<table cellspacing="5" cellpadding="0" width="95%">
<thead style="background-color:#DDDD00;">
<tr>
<td align="right" style="font-size:15pt;font-weight:bold;font-family:arial;">:חדשות</td>
</tr>
</thead>
<tbody id="news">

</tbody>
</table>
</center>
<!-- here is the footer style of the page-->
here is the php:

<?php
//here includes the config
// how many rows to show per page
$rowsPerPage = 5;

// by default we show first page
$pageNum = 1;

$query = "SELECT * FROM news LIMIT 5";
$result = mysql_query($query) or die('Error:4;');

// print the random numbers
while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>';
echo '<table cellspacing="0" align="center" width="100%">';
echo '<tbody align="right" style="background-color:white;">';
echo '<tr>';
echo '<td>';
echo $row['text'];
echo ' </td>';
echo '</tr>';
echo '</tbody>';
echo '<tfoot style="background-color:#DDDD00;">';
echo '<tr>';
echo '<td colspan="5" align="right">'.$row['date'].'</td>';
echo '</tr>';
echo '</tfoot>';
echo '</table>';
echo '</td>';
echo '</tr>';
}

?>
the problem is that it doesn't put the response text in the table body with the id news

shyam
11-14-2007, 05:50 AM
whats not working? exactly

shedokan
11-14-2007, 11:49 AM
oh yea, forgot.
the problem is that it doesn't put the response text in the table body with the id news.

shyam
11-14-2007, 12:09 PM
did u check if the news.php is returning any results by putting its url in a browser?

shedokan
11-14-2007, 01:07 PM
yes here's a link to news.php:
http://neostar.110mb.com/news.php
and here's a link to the page:
http://neostar.110mb.com/test.php

shedokan
11-14-2007, 11:07 PM
now here's where I am:
the script is working only in firefox and not in IE.
here is the new ajax script:

<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function createXMLHttpRequest(){
var ajaxRequest; // The variable that makes Ajax possible!

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}
function callback(id){
if (xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById(id).innerHTML=xmlHttp.responseText;
}else{
document.getElementById(id).innerHTML="Cannot find page: " + xmlHttp.status;
}
}else{
document.getElementById(id).innerHTML="Waiting for server...";
}
}
function ajaxFunction(){
// Create a function that will receive data sent from the server
var newsDisplay = document.getElementById("news");
document.getElementById("news").innerHTML="Starting...";
xmlHttp=createXMLHttpRequest();
xmlHttp.onreadystatechange=function(){callback("news")};
xmlHttp.open("GET", "news.php'.$page.'", true);
xmlHttp.send(null);
}
window.onload=function(){ajaxFunction()};
//-->
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum