How to upload a PHP file to a DIV using jQuery?

I am developing a website and I have this in 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, I am trying to load home.php when I click on the Contact Us hyperlink, which does not work. What is wrong with my code?

+7
source share
4 answers

add home.php URL to the page instead of the file name.

 $(document).ready(function(){ $("#contact").click(function(){ $("#contents").load('url to home.php'); }); }); 
+15
source

You can use $.load() like this to get more data about what is going on. When you see the error message, you can probably 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); } }); 
+8
source

@ user2805663 I know this post is pretty old, but although I can post a solution that can help someone else, as it helped me.

Thanks @Mangala Edirisinghe

using the following method, you can upload two separate files in two different DIVs with a single click (Link).

 $(document).ready(function(){ $("#clickableLink").click(function(){ $("#contents").load('url/file1.php'); $("#contents2").load('url/file2.php'); }); }); 
+2
source

You should use the path " home.php " from the dir index, not from the script dir.

If you are on the site:

 / index.php scripts /script.js /home.php 

You need to change the parameter " scripts / home.php "

+1
source

All Articles