1

我正在使用 Lamp 服务器和 Laravel php 框架。我的问题是,我无法正确实现 Ajax。它似乎有效,div#content 以我想要的方式改变,但地址看起来很相似:

~ytsejam/wlog/public/#http://localhos./~ytsejam/wlog/public/index.php/a

在萤火虫控制台我得到这个错误:

Error: Syntax error, unrecognized expression: [hash=#http:/~ytsejam/wlog/public/index.php/a]
[Break On This Error]   
...{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAt...
jquery.min.js (line 3)

这是我的 ajax 代码:

$(document).ready(function() {  

    // Check for hash value in URL  
    var hash = window.location.hash.substr(1);  
    var href = $('#sidebar-content ul li a').each(function(){  
        var href = $(this).attr('href');  
        if(hash==href.substr(0,href.length-5)){  
            var toLoad = hash+'.html #content';  
            $('#page').load(toLoad)  
        }   
    });  

    $('#sidebar-content ul li a').click(function(){  

    var toLoad = $(this).attr('href')+' #content';  
    $('#content').hide('fast',loadContent);  
    $('#load').remove();  
    $('#wrapper').append('<span id="load">LOADING...</span>');  
    $('#load').fadeIn('normal');  
    window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);  
    function loadContent() {  
        $('#page').load(toLoad,'',showNewContent())  
    }  
    function showNewContent() {  
        $('#page').show('normal',hideLoader());  
    }  
    function hideLoader() {  
        $('#load').fadeOut('normal');  
    }  
    return false;  

    });  
}); 

我该如何解决这个哈希问题?

4

0 回答 0