Ok I am trying to write a script which works great except that it doesnt stop loading.
Usually I don’t just post all my code but in this case I just can’t find the problem and I hope someone of you guys does.
On the actual page i have a little code like this
[CODE]<script type=”text/javascript” src=”http://mydomain/vcardjs.php”></script>
<script type=”text/javascript”>
vcard_id=1;
vcard();
</script>
right now I have a file that does some php and some javascript stuff
The code for that one is
[CODE]
<?php
if (isset($_GET[‘id’])) {
mysql_connect(‘localhost’,’xxx’,’xxx’);
mysql_select_db(‘xxx’);
$sql = ‘SELECT displayname FROM vcard WHERE id=’.$_GET[‘id’].’ LIMIT 1′;
$query = mysql_query($sql);
$result = mysql_fetch_assoc($query);
?>
document.write(‘<a href=”http://mydmain/vcard.php?id=<?php echo
$_GET[‘id’];?>”><img src=”http://mydomain/img/vcard.png”> <?php echo $result
[‘displayname’];?> </a>’);
<?php
exit;
}
else {
header(‘Content-type: application/javascript’);
?>
function vcard() {
function ajax_do (url) {
var jsel = document.createElement(‘SCRIPT’);
jsel.type = ‘text/javascript’;
jsel.src = url;
document.body.appendChild (jsel);
}
ajax_do (‘http://mydomain/vcardjs.php?id=’+vcard_id);
}
<?php
}
?>
The file above works this way
if there is no variable id set in the querystring the javascript gets run. The javascript does some kind of ajax request to get some text. The request is made to the same file just with the query variable id set to the value of the variable on the main page.
The php code simply does a query to the database and then creates a javascript code.
Not sure If I make sense at all, I hope I do.
Like I said the code works fine it just doesn’t stop loading.
Any ideas? Any need to explain some more?