0

I tring to load PHP file with ajax without refreshing the all page and it is not work. I have this code:

    <html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$('#gohomw').click(function(){
   $("#center").load("home.php");
   return false;
});
</script>
</head>

and this is my div:

<a href="#" id="gohomw">go home</a>
<div id="center"></div>

when i click on "go home" nothing happens, any idea?

3 Answers 3

3

There is no element with the specified id at the time the script runs. Move the script so it appears after the element you are trying to bind the event handler to.

Sign up to request clarification or add additional context in comments.

Comments

3

You have to do action like that when the DOM is ready to use.

Place your JavaScript code in this snippet:

$( document ).ready(function() {
  // Handler for .ready() called.
});

You can have more informations here: http://api.jquery.com/ready/

Comments

0

Use below js code for ajax call

$('#gohomw').click(function(){
    $.ajax({
             type: "POST",
             url: "home.php",
             data: datas,
             cache: false,
             success: function(html){

             }
           });
});

Comments

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.