0

我对整个 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 上。提前致谢。

4

1 回答 1

0

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

于 2012-06-10T14:28:47.107 回答