external javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sanchougule
Forum Newbie
Posts: 1
Joined: Tue Jan 20, 2009 11:15 pm

external javascript

Post by sanchougule »

<?
//"ip.php" example- display user IP address on any page
Header("content-type: application/x-javascript");
$serverIP=$_SERVER['REMOTE_ADDR'];
echo "document.write(\"Your IP address is: <b>" . $serverIP . "</b>\")";
echo"alert("\hello\")";
?>And once called by external JavaScript:

<script type="text/javascript" src="ip.php"></script>

the code echo"alert("\hello\")";
is not executing please give a solution
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: external javascript

Post by requinix »

You're mixing up types: application/x-javascript and text/javascript. Pick one MIME type and stick with it.

To be specific, use the latter.
Post Reply