I am developing a website and I have this on the side menu :
<a href="#" class="leftMenu" id="contact">Contact Us</a>
then I have this script
$(document).ready(function(){
$("#contact").click(function(){
$("#contents").load('home.php');
});
});
and I have this DIV inside my page :
<div class="contentWrapper" id="contents"></div>
Obviously, what I am trying to do is to load home.php when I click on the Contact Us hyperlink, which doesn't work. What is wrong with my code?
The DOMDocument::load() function is an inbuilt function in PHP which is used to load an XML document from a file. Parameters: This function accepts two parameters as mentioned above and described below: $filename: This parameter holds the path to the XML document.
jQuery load() Method The load() method loads data from a server and puts the returned data into the selected element. Syntax: $(selector). load(URL,data,callback);
You can use jQuery to support both synchronous and asynchronous code, with the `$.
$(document). ready(function(){ if (jQuery) { // jQuery is loaded alert("Yeah!"); } else { // jQuery is not loaded alert("Doesn't Work"); } });
You can use $.load()
like this, to get more data of whats happening. When you see the error message, you probably can solve it yourself ^^
$("#contents").load("home.php", function(response, status, xhr) {
if (status == "error") {
// alert(msg + xhr.status + " " + xhr.statusText);
console.log(msg + xhr.status + " " + xhr.statusText);
}
});
add home.php
page url instead of file name.
$(document).ready(function(){
$("#contact").click(function(){
$("#contents").load('url to home.php');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With