0

Hi everybody :)

I have a very stupid answer but I cannot solve it!

Connect to the mysql db, I get the records that are URLs, into the php loop I call an ajax function that reads the title tag address of the URL

ajax code

function getTitle(str1,str2)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("titleTag_"+str2+"").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","url_title.php?url_name="+str1+"",true);
xmlhttp.send();
}

php code

<?php
while ($fields = @mysql_fetch_array($Query)) {
// call function that reads the title tag for each URL Listed
?>
<script type="text/JavaScript">
<!--
new getTitle('<?php echo $fields['url']; ?>', '<?php echo $fields['idOfUrl']; ?>');
-->
</script>
<div id="tagTitle_<?php echo $fields['idOfUrl']; ?>">HERE OUTPUT</div>
<?php
}
?>

but this "dirty" method does not work 'cause I think the function does not have time to read!
however..
if I change page and go back in browser window titles are shown correctly, then the function is written correctly

how can I solve it?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by diafol
0

This seems very wasteful with regard to server calls. Does this run on page load? If so, what's the point of using Ajax? Just get the info via php.

Edited by diafol: n/a

0

hi
surely you're right
but reading a file (as can be an external address) requires time that I wanted to save by using ajax.. so I think this is a method, if you have other solution(s) please tell me..
thanks

0

You can read as many files as you want in php - you don't need ajax to do it. I just don't understand what you're trying to do.

Getting ALL the info before the browser accepts it (server processing) is much better than making server calls -> client calls -> server calls - if that is indeed what you're doing. Sorry if I've got the wrong end of the stick.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.