Ingolme Posted February 14, 2015 Share Posted February 14, 2015 Where is that appearing? On which page? Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Well, my test.php file has this code: <?phpecho(rand(10,100));?> Once javascript runs on my localhost and performs the Ajax request it returns this code in between the div tag with id "demo": <!--?phpecho(rand(10,100));?--> Basically, when I right click on the page and click "Inspect Element" this appears (this is my Source Code): <div class="entry-content"><p><br><br><br> <script type="text/javascript" src="http://localhost:8888/.../javascript/test.js"></script><br><br></p><div id="demo"><!--?phpecho(rand(10,100));?--></div><p><br></p></div> I put in "..." in the script path to shorten the URL. Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 Javascript is working exactly as it should. It sounds like PHP is not being parsed. Open test.php right in your browser and press Control+U to see actual the source code. 1 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Ok, I have done that. I opened the file in three different browsers and the source code is: <?php echo(rand(10,100)); ?> This is just as the code the file contains. Once it gets parsed it seems like Ajax does not recognize the PHP code and adds "!--" and "--". Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 This is a problem. PHP isn't being parsed. Your server is just sending the code straight to the browser without running it. What the browser should get when you open that page is a number, not PHP code. 1 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Has it something to do with the fact that I run Wordpress? Wordpress is based on PHP and logically it must work. How can I make sure that PHP is run before it is sent to the browser? Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 No, Wordpress doesn't have anything to do with it unless you're actually loading Wordpress code inside test.php What is the complete URL in the browser 's address bar when you open test.php? Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 http://localhost:8888/test-site/wp-content/my-php-files/test.php <-- When I access the file through my localhost Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Sorry for the blank posts. There is an issue the link does not get published! Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 THis is the link when I open the file directly from my documents: Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 Unfortunately nothing's showing up in your posts. The file does have a .php extension so I don't know why the PHP isn't being parsed. Is this the URL you're using in your Javascript code? http://localhost:8888/test-site/wp-content/my-php-files/test.php 1 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 "view-source:file://localhost/Applications/MAMP/htdocs/test-site/wp-content/my-php-files/test.php" Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 No I have managed to get the link published. Really sorry about that. Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 Yes, indeed. The complete URL of the file is in the javascript code. Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 I'm not sure if this is the one you're using, but this URL won't work: file: // localhost/Applications/MAMP/htdocs/test-site/wp-content/my-php-files/test.php You need to use http://localhost to make the PHP run. 1 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 14, 2015 Author Share Posted February 14, 2015 I use localhost if not any page would not be loaded. I was not sure which url you needed so I provided both. My Ports are as follows: Apache Port: 8888 Nginx Port: 7888 MySQL Port: 8889 My PHP version is 5.6.2 and my Webserver is Apache. Hope this helps, as perhaps this problem ay have to do with the ports. What would you suggest? Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 The Javascript is working as it is supposed to. The server just seems to not be executing the PHP code. I can't think of any reason why it's not working. Try making a new PHP file test2.php in the same directory and open it in the browser. Make it simple: <?php echo 'Hello, World!'; ?> 1 Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 15, 2015 Author Share Posted February 15, 2015 Ok, I have tried that as well. Still the same. The browser does not process the php and just displays <?php echo 'Hello, World!'; ?> instead of showing "Hello World". Link to comment Share on other sites More sharing options...
Ingolme Posted February 15, 2015 Share Posted February 15, 2015 How about if you put the file right at the root of the website? Directly at http://localhost:8888/test2.php Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 15, 2015 Author Share Posted February 15, 2015 Yes, I tried that already. I tried renaming the file and other tricks as well. How can I upload pictures here? Maybe I can send some screenshots so that you can see how my localhost looks like and some other screenshots which may be of use furthermore. Moreover, when I click on "Inspect Element", go to the network tab and click on refresh I can see all the movement that happens. One of them is the the Ajax Request with the type "POST" and Status 200 (OK). I have been doing some research but sadly I found nothing useful regarding this subject. Does it have to do with the fact that I use Caching Plugins? I use W3 Total Cache in order to cache browser data, minify scripts, etc. I also use an Autoptimize tool that optimizes HTML, CSS, and Javascript but I doubt that this last tool has anything do with as all other scripts work, and in this case scenario the script seems to be working fine. To be honest this is a mistery to me. Link to comment Share on other sites More sharing options...
ava_barbilla Posted February 15, 2015 Author Share Posted February 15, 2015 I added some html to the php file and everything loads except the php file (php appeared as a comment). Then, I came up with the idea to compare the php file I created with the other php files on my local server. I identified a little difference. The other php files do not close the php, i.e. <?php echo 'Hello World'; without putting "?>" at the end, and now it works. My php file looks like this: <?phpecho 'Hello World'; I also simplified my script, making my structure look like follows: <div id="demo"><div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script>$(document).ready( function() {$('#demo').load('http://localhost:8888/test-site/wp-content/my-php-files/test3.php');});</script> I used JQuery .load() property as it is simpler than the normal script (same principle). The only thing I have to do now is to apply a setIntervl to load the function after a specific amount of time and I am finished. Thanks for the support Ingolme. I learned a lot today with your help. Link to comment Share on other sites More sharing options...
Ingolme Posted February 15, 2015 Share Posted February 15, 2015 While the closing ?> tag is not required for PHP to function, having it there should not actually change the functionality of the program either. I am completely confused as to what your server is doing. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now