I have that div:
<div id="content"></div>
and I want to include inside PHP file using jQuery.
I try with this, but doesn't work:
var about_me = "<?php include('php/about_me.php') ?>"
$('$content').click(function(){
$('#content').text(about_me);
});
This returns me PHP code like a string?
We can't use "PHP in between JavaScript", because PHP runs on the server and JavaScript - on the client. However we can generate JavaScript code as well as HTML, using all PHP features, including the escaping from HTML one.
The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
You could use .load
:
$("#content").load('/about_me.php');
Is it a .php file? IF it's a .js or .html file, Apache (or whatever webserver you're using) won't interpret it as a PHP file and won't include the relevant file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With