0

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:

<html>
<body>
    <div id="web_Logo">
        <h1>Website Logo</h1>
    </div>
    <div id="web_Menu">
        <ul>
            <li><a href="index.php">Home</a></li>
            <li><a href="help.php">Help</a></li>
            <li><a href="contact.php">Contact</a></li>
        </ul>
    </div>
    <div id="web_Content">
        //CONTENT LOADS HERE//
    </div>
</body>
</html>

What would be the best way to load a page (help.php or contact.php for example) using AJAX into the contents Div section?

I am using the JQuery library for my site if that helps.

1
  • 1
    Please... I beg you... don't do your entire site like this with Javascript. Simple server-side includes are easy with PHP. Commented Apr 8, 2011 at 18:42

3 Answers 3

8
  $('#web_Content').load('myFile.php');
Sign up to request clarification or add additional context in comments.

Comments

1

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');
        });
    });
});

Comments

0
<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.

1 Comment

What is the Jquery script needed here? I don't have the library loaded or anything, but could you give a step by step for me of how to do basically the same thing that the author of this thread was mentioning?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.