尽管页面存在,Jquery AJAX仍未加载页面

时间:2012-06-10 13:47:37

标签: javascript jquery ajax

我对整个AJAX事情比较陌生,我正在编辑一个打开模态框的脚本,然后将所请求的内容加载到所述框中。我有以下Javascript

jQuery(document).ready(function($){

$('a[name=modal]').click(function(e) {

    e.preventDefault();

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set height and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});  
    $('#mask').fadeTo(600,0.75); 

    var load_page = $(this).attr('ajax');

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    // Set the loading HTML to be displayed
    var loadingHTML = '<center><img src="_img/progress_bar.gif"/></center>';

        //Set the loading bar
        $('#placeholder').html(loadingHTML).fadeTo(600,1);
        $('#placeholder').css('top',  winH/2-$('#placeholder').height()/2);
        $('#placeholder').css('left', winW/2-$('#placeholder').width()/2);

    // Ajax load
    $('#ajax').load('_content/' + load_page + '.php', null, function(){  
        $('#ajax').css('top',  winH/2-$('#ajax').height()/2);
        $('#ajax').css('left', winW/2-$('#ajax').width()/2);
        $('#ajax').fadeTo(600,1);
    });   

});

$('.window .close').click(function (e) {
    e.preventDefault();
    $('#mask, #box, #ajax').hide();
});    

//if mask is clicked
$('#mask').click(function () {
    $(this).hide();
    $('#ajax, #placeholder').hide();
});        

});

还有以下HTML,

<div id="mask"></div>
<div id="placeholder"></div>
<div id="ajax"></div> 

我的CSS也是,

    #mask 
{
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  z-index: 9000;
  background: url("../_img/mask.png") repeat;
  display: none;
  overflow: hidden;
}
#placeholder
{
    overflow: hidden;
    opacity: 0;
    position: absolute;
    z-index: 9050;
    overflow: hidden;
}
#ajax
{
    position: absolute;
    z-index: 9100;
    overflow: hidden;
    opacity: 0;
    display: none;
}

脚本显示加载栏但不显示带有AJAX内容的模态框,该页面确实存在于我的Localhost上。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我认为这是因为该网站无法找到_content文件夹,因为它可能与javascript文件不在同一目录中。尝试../_content,如果这不起作用,只需尝试使用整个网址:http://example.com/a/b/_content/ ...