How to load PHP file into DIV by jQuery?

前端 未结 4 711
轮回少年
轮回少年 2020-11-27 17:23

I am developing a website and I have this on the side menu :

Contact Us

then I h

相关标签:
4条回答
  • 2020-11-27 18:06

    add home.php page url instead of file name.

    $(document).ready(function(){
      $("#contact").click(function(){
        $("#contents").load('url to home.php');
      });
    });
    
    0 讨论(0)
  • 2020-11-27 18:06

    You have to use the path of "home.php" from index dir and not from script dir.

    If you site is :

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

    You have to modify your parameter passing "scripts/home.php"

    0 讨论(0)
  • 2020-11-27 18:10

    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);
      }
    });
    
    0 讨论(0)
  • 2020-11-27 18:28

    @user2805663 I know this post is pretty old but though let me post the solution it might help someone else, as it helped me.

    Thanks to @Mangala Edirisinghe

    by following method you can load two separate files in two different DIVs with single click(Link).

    $(document).ready(function(){ 
     $("#clickableLink").click(function(){ 
      $("#contents").load('url/file1.php');
      $("#contents2").load('url/file2.php'); 
     }); 
    });
    
    0 讨论(0)
提交回复
热议问题