Jordan
Jordan

Reputation: 489

How to include php file using Jquery?

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?

Upvotes: 5

Views: 30188

Answers (3)

Deepak Soni
Deepak Soni

Reputation: 210

this is a simple way that you can do it. Just do it.

just put the file name in .load function

$(function(){  $("#includedContent").load("header.php"); });

Upvotes: 0

xdazz
xdazz

Reputation: 160833

You could use .load:

$("#content").load('/about_me.php');

Upvotes: 17

StackOverflowed
StackOverflowed

Reputation: 5975

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.

Upvotes: 2

Related Questions