External JavaScript and PHP Problem

Reply

Join Date: Mar 2008
Posts: 39
Reputation: CasTex has a little shameless behaviour in the past 
Solved Threads: 0
CasTex CasTex is offline Offline
Light Poster

External JavaScript and PHP Problem

 
0
  #1
Mar 31st, 2008
Can someone tell me where is the problem ?


  1. <script type="text/javascript" src="http://www.forumistan.net/analiz/analiz.php?site=http://www.forumistan.net"></script>

analiz.php

  1. <?
  2. Header("content-type: application/x-javascript");
  3. ob_start();
  4. include 'all.php';
  5. ob_end_clean();
  6. echo "document.write(\"<div class=\"txt\">Pagerank: $rank->pagerank <br>\")";
  7. echo "document.write(\"Alexa: $rank->alexa_rank</div>\")";
  8. ?>
Last edited by CasTex; Mar 31st, 2008 at 3:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 150
Reputation: sDJh is an unknown quantity at this point 
Solved Threads: 13
sDJh sDJh is offline Offline
Junior Poster

Re: External JavaScript and PHP Problem

 
0
  #2
Mar 31st, 2008
try:
  1. echo "document.write(\"<div class=\"txt\">Pagerank: ".$rank->pagerank." <br>\")";
  2. echo "document.write(\"Alexa: ".$rank->alexa_rank."</div>\")";
in the PHP-code.
If it doesn't help then open that JS directly in your browser and tell us the error-reporting.
Last edited by peter_budo; Apr 1st, 2008 at 7:11 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 39
Reputation: CasTex has a little shameless behaviour in the past 
Solved Threads: 0
CasTex CasTex is offline Offline
Light Poster

Re: External JavaScript and PHP Problem

 
0
  #3
Mar 31st, 2008
I tried it, but still it is a blank...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: RoryGren is an unknown quantity at this point 
Solved Threads: 8
RoryGren's Avatar
RoryGren RoryGren is offline Offline
Junior Poster in Training

Re: External JavaScript and PHP Problem

 
0
  #4
Apr 1st, 2008
I see you are using ob_end_clean() - that clears the Output buffers and turns off output buffering. I am not sure, but that might mean that your include 'all.php'; will not be used at all.

Try removing that line - ob_end_clean(); - and then at the very end of your code on that page, have ob_end_flush();
The OB functions are for Output Buffering - ob_start() holds all php output in the buffer until it receives the ob_end_flush() command. Then is sends all the output to the browser and clears the buffer.

ob_end_clean() just clears the buffers without sending the contents to the browser.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 11
Reputation: Yayo_SK is an unknown quantity at this point 
Solved Threads: 1
Yayo_SK Yayo_SK is offline Offline
Newbie Poster

Re: External JavaScript and PHP Problem

 
0
  #5
Jan 17th, 2009
Try this:

<?PHP
Header("content-type: application/x-javascript");
ob_start();
include 'all.php';
ob_end_clean();
echo "document.write(\"<div class=\"txt\">Pagerank: $rank->pagerank <br>\")";
echo "document.write(\"Alexa: $rank->alexa_rank</div>\")";
?>

Problem is at the first line. I think. Maybe.
Last edited by peter_budo; Jan 18th, 2009 at 2:14 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: External JavaScript and PHP Problem

 
0
  #6
Jan 17th, 2009
try using a different content type like text/javascript.

and capitalizing the php start tag does nothing.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 11
Reputation: Yayo_SK is an unknown quantity at this point 
Solved Threads: 1
Yayo_SK Yayo_SK is offline Offline
Newbie Poster

Re: External JavaScript and PHP Problem

 
0
  #7
Jan 17th, 2009
I did not mean capitalizing php start tag. I mean "FULL" php start tag "<?php" because XML files has the same start tag "<?xml".
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: External JavaScript and PHP Problem

 
0
  #8
Jan 17th, 2009
ok, sorry. i saw the capitalized PHP in red and thought you meant to capitalize it. i didn't see s/he didn't use the full start tag in the original post.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,336
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: External JavaScript and PHP Problem

 
0
  #9
Jan 18th, 2009
this is a short script file in php that works
file:: script.js.php
  1. <?php header ('content-type: text/javascript');
  2. ob_start("ob_gzhandler"); ?>
  3. function newuntill(date) {
  4. var newimg = "./images/new.gif";
  5. var expdate = new Date(date);
  6. var curdate = new Date();
  7. if (expdate.getTime() > curdate.getTime()) {
  8. document.write('<img align="left" src=' + newimg + '>');
  9. }
  10. else {
  11. document.write('');
  12. }
  13. }
  14. function movein(which,html) {
  15. which.style.background='turquoise'
  16. window.status=html
  17. }
  18. function moveout(which) {
  19. which.style.background='#d4d0c8'
  20. window.status=''
  21. }
  22. <?php ob_flush(); ?>
header ('content-type: application-x, .........
looks for an external handler,
javascript is supposed to run in the browser

gzhandler, compresses the files before sending
Last edited by almostbob; Jan 18th, 2009 at 1:30 am.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 81
Reputation: it2051229 is an unknown quantity at this point 
Solved Threads: 1
it2051229 it2051229 is offline Offline
Junior Poster in Training

Re: External JavaScript and PHP Problem

 
0
  #10
Jan 18th, 2009
"<script type="text/javascript" src="http://www.forumistan.net/analiz/analiz.php?site=http://www.forumistan.net"></script>"

that's not the right way to do it.. the code above does not call an external javascript
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC