alphazulu Posted May 10, 2011 Share Posted May 10, 2011 Hello, I am having some issues with a project I am working on. I am calling a php file on another server using <script type="text/javascript" src="http://www.website.com/test/file.php"></script> I have the correct type header in my php file and the php outputs JS. example echo "document.write(\"some stuff\");"; that kind of thing happens alot I also have it outputting a few JS functions, example echo 'function dostuff(){ stuff }'; the problem I am having is when I add the JS call to the page that calls the php it does nothing I am using document.ready I am not really sure where to go from here, I know php well enough to do anything I need but I do not know JS at all I can not post the actual source code, I know that would be much easier to troubleshoot this but this is something I just can not do. Also this needs to be done this way, I need to call to php files on another server so they can do some stuff and then use JS to change some things on another page on another server. This is a content locker, a lot like CPALead and things like that. What am I missing? Any help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/ Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 Did you try debugging what is going on using firebug? Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213195 Share on other sites More sharing options...
alphazulu Posted May 10, 2011 Author Share Posted May 10, 2011 never used it before, gonna check it out now Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213197 Share on other sites More sharing options...
alphazulu Posted May 10, 2011 Author Share Posted May 10, 2011 Ok Now I see what is happening, but still at a loss for some reason. Could be because I have been working on this for 10 hours today, or maybe I don't know what to do here. it is simply printing the JS as text, I can post this since its nothing this is what firebug shows me <html> <head> <script src="http://www.lightspeedmedia.net/test/contentlocker.php" type="text/javascript"> function setupgateway(){ var Left = $(window).width() /2; Left = Left - $('#gatewaydiv').width()/2; var Top = $(window).height() /2; Top = Top - $('#gatewaydiv').height()/2; $('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline'); $('#gatewayDimmer').width($('html').width()); $('#gatewayDimmer').height($('html').height()); $('#gatewayDimmer').css('display','block');}function removegateway(){ $('#gatewaydiv').css('display', 'none'); $('#gatewayDimmer').css('display','none');}document.write("<meta http-equiv="refresh" content="5 ">);document.write("<link rel="stylesheet" type="text/css" href="style.css" />");document.write("<div id="gatewayDimmer"></div>");document.write("<div id="gatewaydiv">");document.write("<ul id="OfferList">");document.write("<h1>You Must Complete An Offer To Unlock Page </h1>");document.write("<span id="gatewayMessage">Files Locked </span>");document.write("<br /><br />");document.write("<li><center><a href="www.website.com " class="offerlink" target="blank">Click Here Man </a></center></li>");document.write("<li><center><a href="www.website.com " class="offerlink" target="blank">Click Here </a></center></li>");document.write("<li><center><a href="www.website.com " class="offerlink" target="blank">Click Here </a></center></li>");document.write("<li><center><a href="www.website.com " class="offerlink" target="blank">Click Here </a></center></li>");document.write("</ul><br /><br /><center><h3><b>This page will automatically refresh once the offer is finished </b></h3></center></div>");$(document).ready(function() { setupgateway(); }); </script> </head> <body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213202 Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 In the contentlocker.php script comment out the header() call and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213204 Share on other sites More sharing options...
alphazulu Posted May 10, 2011 Author Share Posted May 10, 2011 No change This is odd to me, I did a lot of small scale testing, but when it comes to the final it outputs this only Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213205 Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 Well... this code makes use of jquery. I didn't look that carefully at your script but I don't see where you're including the jquery library. Also, your page snippet is not well formed, and there is none of the divs that are referenced or for that matter markup of any kind. It's not going to work if you don't have a well formed html document. Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213209 Share on other sites More sharing options...
alphazulu Posted May 10, 2011 Author Share Posted May 10, 2011 hmm jquery, will fix that. it references an external .css, which is actually made by the php file when the script is run, which works just fine I will work on reforming it, but this is ultimately going to work on any page where the correct call to the .php file is made. I will let you know if i can get it to work Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213211 Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 That entire script is 100% dependent on jquery. $(document).ready is jquery. Best/fastest way is to source it from the Google CDN: http://docs.jquery.com/Downloading_jQuery#CDN_Hosted_jQuery Quote Link to comment https://forums.phpfreaks.com/topic/235984-help-with-calling-a-php-with-js/#findComment-1213212 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.