Home Internet Load PHP File In Specific Div After Page Load Using JQuery

Load PHP File In Specific Div After Page Load Using JQuery

0
SHARE

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 .

Must read : What is CSS ?  and what is Id in css ?

Example Source Code

<div id="insert-file"></div>
<script type="text/javascript">
$(document).ready(function(){
$('#insert-file').load('http://example/folder/custom.php');
});
</script>
</body>

 Steps

  • Create a <div> with Id name “insert-file” . This is the container where you want to insert php file .  In this example i create
<div id="insert-file"></div>
  • 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 .
READ ALSO : -  PHP Lessons- Create An Array In PHP Programming

Note: Don’t forget to link jquery file at head section of web page before run the code .Load Jquery On Webpage ?

Working

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 .

What is a built in function ?

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 .