megetron Posted January 20, 2012 Share Posted January 20, 2012 Hello all, I am trying to create a link tracker. I created a javascript file : trackincode.php?lid=1 and in it this line: Response.Write("document.write(\"Hello World\");"); Now, I want to call this file from an HTML file, so I copy/paste this HTML: <script language='javascript' type='text/javascript'> var r=document.referrer; var counter = new Object(); counter.src = 'http://domain.com/trackingcode.php?lid=7&r='+r; </script><script src=http://domain.com/trackingcode.php?lid=7> </script> unfortunattly the code does not display the text "Helloo World" and the file is not executed... Any suggestions? NOTE: I know this code works on another servers... Quote Link to comment https://forums.phpfreaks.com/topic/255410-how-do-i-execute-a-php-page-from-html-using-javascript/ Share on other sites More sharing options...
megetron Posted January 20, 2012 Author Share Posted January 20, 2012 Response.Write("document.write(\"Hello World\");"); Oops..I meant: echo "document.write(\"Hello World\");"; Quote Link to comment https://forums.phpfreaks.com/topic/255410-how-do-i-execute-a-php-page-from-html-using-javascript/#findComment-1309505 Share on other sites More sharing options...
Adam Posted January 20, 2012 Share Posted January 20, 2012 Response.write() - is this wrapped in ASP or something? Can you show the full code of trackingcode.php? Quote Link to comment https://forums.phpfreaks.com/topic/255410-how-do-i-execute-a-php-page-from-html-using-javascript/#findComment-1309520 Share on other sites More sharing options...
megetron Posted January 21, 2012 Author Share Posted January 21, 2012 Response.write() - is this wrapped in ASP or something? please ignore "Response.Write"...my mistake. the full code is this: <?echo "document.write(\"Hello World\");";?> Here you have a link to the file (I rename the file to "get_trackingcode1.php") http://affilinn.co.il/get_trackingcode1.php?aid=1&linkid=N1 I expect to see "Hello World" text when calling the page using javascript. Quote Link to comment https://forums.phpfreaks.com/topic/255410-how-do-i-execute-a-php-page-from-html-using-javascript/#findComment-1309882 Share on other sites More sharing options...
nogray Posted January 22, 2012 Share Posted January 22, 2012 Make sure to set the http headers to javascript header("Content-type: text/javascript"); Also, you file contains a lot of HTML code which will cause a javascript error and stop it from executing. Quote Link to comment https://forums.phpfreaks.com/topic/255410-how-do-i-execute-a-php-page-from-html-using-javascript/#findComment-1309964 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.