/    Sign up×
Community /Pin to ProfileBookmark

javascript doesnt stop

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> [/CODE]

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
}
?>

[/CODE]

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?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooNov 26.2007 — window.onload=function(){document.close()}
Copy linkTweet thisAlerts:
@stephan_gerlachauthorNov 26.2007 — Where would I put this?
Copy linkTweet thisAlerts:
@mrhooNov 26.2007 — in the head of the document, or in any script that is loaded in the head of the document, or in a script element anywhere on the document.

If you open a textstream with document.write and it is not some browser specific number of bytes, or the whole command is part of an echo or a write itself, the write function is waiting for more input, keeping the download open, until document.close() is explicitly called.
×

Success!

Help @stephan_gerlach spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...