Skip to content Skip to sidebar Skip to footer

How To Load A PHP Script Using AJAX?

I would like to know the best technique for loading a PHP page and insert into a section of a page using AJAX? For example, consider the following HTML code:

Solution 1:

  $('#web_Content').load('myFile.php');

Solution 2:

I assume you want the page to load in the web_Content div when a link is clicked, If so, you can do something like this:

$(function(){
     $('#web_Menu a').click(function(e){
        e.preventDefault();
        $('#web_Content').load($(this).attr('href'), function(){
            alert('File loaded');
        });
    });
});

Solution 3:

<script src="jquery.js"></script>
// dont forget to include jquery script 

<script type="text/javascript">

function a()
{

   var file="otherfilename"; //Enter the name of file, which is to be loaded 
   $("#load_file").load(file+".php").fadeIn("slow");

}

</script>

<button onClick="a();">Read File</button>

<div id="load_file">  The division where file will be loaded </div>

Easy loading of other .php file using Jquery, simple and easy.


Post a Comment for "How To Load A PHP Script Using AJAX?"