Hello im creating a small social network from scratch and struggling with the newsfeed i have the newsfeed loaded through ajax then page loaded remotly i have a timeago jquery script and the timeago script is not working, but when i get rid of the ajax auto refresh and use the code without the auto refresh it works

here is the coding that wont work

home.php

<script type="text/javascript">
function Ajax(){
var xmlHttp;
	try{	
		xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
		}
		catch (e){
		    try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("No AJAX!?");
				return false;
			}
		}
	}

xmlHttp.onreadystatechange=function(){
	if(xmlHttp.readyState==4){
		document.getElementById('Comments').innerHTML=xmlHttp.responseText;
		setTimeout('Ajax()',100);
	}
}
xmlHttp.open("GET","feed.php",true);
xmlHttp.send(null);
}

window.onload=function(){
	setTimeout('Ajax()',100);
}
</script>

<div id="Comments">
</div>

feed.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script src="jquery.timeago.js" type="text/javascript"></script>
    <script src="test_helpers.js" type="text/javascript"></script>
    <script type="text/javascript">
      jQuery(document).ready(function($) {
        prepareDynamicDates();
        $("abbr.timeago").timeago();
      });

    </script>
<!-- the above code is the timeago script -->
<?php
$query = mysql_query("SELECT * FROM user_streams WHERE wall_id = '$uid' order by id desc limit 0,25");
		while ($get_info_user = mysql_fetch_array($query))
		{
			$get_info = mysql_query("SELECT * FROM user WHERE user_id = '$get_info_user[user_id]'");
			$get_in = mysql_fetch_array($get_info);
			$del = "";
			$date = $get_info_user[created];
			
			if($user_id == $get_in[user_id])
			{
				$del = "<a href=\"#\"><img border=\"none\" src=\"../icons/btn_window_close.gif\"></a>";
			}
			echo "
			<table width=\"80%\">
			<tr>									
			<td width=\"7%\"><img src=\"../images/avatarpic-s.png\" border=\"none\" align=\"absmiddle\" /></td>
			<td width=\"87%\"><a href=\"profile.php?id=$get_in[user_id]\" style=\"text-decoration:none;\"><b>$get_in[full_name]</b></a></td>
			<td align=\"right\">$del</td>
			</tr>
			<tr>
			<td width=\"7%\"></td>
			<td width=\"87%\">$get_info_user[message]</td>
			</tr>
			<tr>
			<td width=\"7%\"></td>


// this line is what uses the time ago and show change $date into %minutes ago
      \/   \/    \/    \/  

<td width=\"87%\"><abbr class=\"timeago\" title=\"$date\"></abbr>
			<img src=\"../icons/thumb_up.png\">&nbsp;<a href=\"#\" style=\"text-decoration:none\">&nbsp;Like&nbsp;</a>&nbsp;&middot;&nbsp;
			<img src=\"../icons/thumb_down.png\">&nbsp;<a href=\"#\" style=\"text-decoration:none\">&nbsp;Dislike&nbsp;</a>&nbsp;&middot;&nbsp;
			<img src=\"../icons/pencil.png\">&nbsp;<a href=\"#\" style=\"text-decoration:none\">&nbsp;Comment&nbsp;</a><br>
			</td>
			</tr>
			<tr>
			<td></td>
			<td></td>
			</tr>
			</table>
			<hr>";
			}
		
			$count = mysql_num_rows($query);
		if ($count == 0)
		{
			echo "
			<table width=\"80%\">
		<tr>
		<td align=\"center\"><h2>No Post's</h2></td>
		</tr>
		</table>
		<hr>";
		}

that wont work but when i copy the feed page into the div box on the home page it all works correctly? why is this and how can i solve it

Member Avatar for diafol

If you're using jQuery, why aren't you using that for ajax?

Anyway, you're posting about a timeago script (js) in a php forum. If you think the issue is php, fine, otherwise think about posting the question in the js forum.

Go step by step. You should start with those comments in another php file and check all are properly work. Then, hook via ajax in another.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.