weixin_33709364 2014-05-16 14:26 采纳率: 0%
浏览 19

Ajax(加载功能)问题

I wanted to use ajax to make my website open links without refreshing whole webside (only content in 1 div is changing, header/footer/navigation is always the same).

In header I added js:

    <script type="text/javascript" src="js/general.js"></script>

Index.php looks like this:

<?php
    include '/gui/header.php'; 
    include '/gui/nawigacja.php'; 
?>

<div id="content"></div>

<?php include '/gui/footer.php'; ?>

And the general.js looks like this:

$(document).ready(function(e) {
    $('#content').load('content/main.php');

    $('ul#slider li a').click(function() {
        var page = $(this).attr('href');
        $('#content').load('content/'+ page + '.php');
        return false;
    });

    $('ul#menu li a').click(function() {
        var page = $(this).attr('href');
        $('#content').load('content/'+ page + '.php');
        return false;
    });
});

It worked well on localhost (xampp), but when I wanted to move it to remote free server to tests, the load function didn't work (website didn't won't to load at all, but when I deleted "$('#content').load('content/main.php');" it started to load, but then my ajax didn't load content, because there were no ajax).

Is there any way to solve this problem? Would be gratefull for any kind of help.

  • 写回答

2条回答 默认 最新

  • 妄徒之命 2014-05-16 14:32
    关注

    Your JS looks fine, I guess that the URL path is not proper. Make it relative to the root directory by adding / in front of content.

    $(document).ready(function(e) {
    
      $('#content').load('/content/main.php');
    
      $('ul#slider li a').click(function() {
        var page = $(this).attr('href');
        $('#content').load('/content/'+ page + '.php');
        return false;
      });
    
      $('ul#menu li a').click(function() {
        var page = $(this).attr('href');
        $('#content').load('/content/'+ page + '.php');
        return false;
      });
    });
    
    评论

报告相同问题?