Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php include using ajax

I'm creating a web page that is built using "modules", in other words the page is put together using other php files.

On one side of my page there is a div container with some links next to it, this div container will be used to hold certain information. The information is held within separate php files that I wont to be able to load into the div container with the links I mentioned earlier.

How would I go about doing this with ajax?

Note: I load the php files with include("");

like image 940
Stanni Avatar asked Mar 30 '26 14:03

Stanni


1 Answers

AJAX shouldn't replace your PHP includes unless there is a particular reason you want to do this (e.g. page load performance is poor and you want to load some sections asynchronously to the rest of the page).

I would carry on using PHP includes, but if you then want to dynamically update those page sections after the first load, you can use Prototype's Ajax Updater.

Bear in mind that this is not like a server-side include; the parts of the page you update, if they are PHP scripts, will not have access to variables that were set in the rest of the page; you'll need to supply these as GET or POST data with the asynchronous request.

like image 118
Ben James Avatar answered Apr 02 '26 03:04

Ben James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!