Insert PHP file using JQuery after page loading
Using JQuery you can control your page loading . You can control when and how the .php page will be loaded . For this ,you need to hold the php file and insert it in specific area of the web page after page loading or during page loading.
For example, you want to load custom.php at the end of the webpage . Then use the following script to load the custom.php file .
Understand the following example .In this example custom.php file is loaded in the “insert-file” named Id of the div .
Example Source Code
- Create a <div> with Id name “insert-file” . This is the container where you want to insert php file . In this example i create
- Create a jquery at the end of the page just before </body> tag . Use document.ready() so your script run after page load . $(document).ready() function is use to hold the file till the whole document is not loaded .
- Next step is locate the container of the webpage where you want to insert the file . to locate it use $(‘#insert-file’).Get the specific <div> by id in this example insert-file is div id.
- After that use the load() function to load the custom.php file and insert in the div .
Note: Don’t forget to link jquery file at head section of web page before run the code .Load Jquery On Webpage ?
In this example load() function is used to load files . load() is a built in function of jQuery .It is used to load files using jquery .
If you have any other Question about the jquery or php , feel to write in the comment box . Or want to share your ideas click on submit guest post .