繁体   English   中英

jQuery AJAX没有加载页面,尽管页面已存在

[英]Jquery AJAX not loading page, despite page existing

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM