2012-09-18 34 views
0

以下是我想要/想要做的事情。尝试在Ajax之前/期间调用调光器/跳动器

有一种形式。该表单有一个提交按钮。提交按钮的onmousedown事件()事件:

<input type='submit' value='Search' name='save' id='save' onmousedown = 'DimOn("test.php", "SearchResultDiv")' /> 

现在,一旦按钮被点击我想要它做的三件事情按正确的顺序。

1)调暗页面。

2)执行Ajax查询并填充搜索结果。

3)删除Dim。

编辑:

使用beforeSend,并在jQuery对象

function DimOn(sUrl, sElement) 
{ 
    jQueryAjax(sUrl, sElement); 
} 

function jQueryAjax(sUrl, sElement) 
{ 
    $.ajax({ 
     url: sUrl, 
     type: 'GET', 
     async: false, 
     cache: false, 
     timeout: 1000, 
     beforeSend: function(){ 
      $('#dim').fadeIn(); 
     }, 
     complete : function(){ 
      $('#dim').fadeOut(); 
     },  
     error: function(){ 
      return true; 
     }, 
     success: function(msg){ 
      if (msg != '') 
       PopulateResponse(msg, sElement, false); 
      else 
       PopulateResponse("An Error Has Occured.", sElement, false); 
     } 
    }); 
} 

目前完整的事件甚至试过,会出现像这样做:

2)执行Ajax查询,并填充搜索结果。

2)昏暗的页面。

3)删除Dim。

结果填充(需要10秒),调光器快速闪烁。

请借给我一手同行的程序员,我对这项技术并不陌生,为什么我会关闭异步,尝试按顺序获取内容,但仍然没有DICE。

+1

您可以用鼠标选中你的代码,然后点击“代码“按钮(看起来像'{}'),它将为您添加非常典型的四个空间垃圾标记。 –

+0

这很好...我总是会点击标有“代码”的按钮......我想我预计这会工作在“代码” – ManovrareSoft

回答

2

我解决了这个问题,使用此功能:

function jax(sUrl, sElement, bEval, sType, bAsync) 
{ 
    $.ajax({ 
     url: sUrl, 
     type: sType, 
     async: true, 
     cache: false, 
     timeout: 30000, 
     error: function() 
     { 
      return true; 
     }, 
     beforeSend: function(){ 
      $('div#dim').fadeIn(400); 
     }, 
     complete : function(){ 
      $('div#dim').fadeOut(200); 
      if(sUrl.search(/scroll=true/ig) != -1) 
       goToByScroll(sElement); 

     },      
     success: function(msg){ 
      if (msg != '') 
      { 
       PopulateResponse(msg, sElement, bEval); 
      } 
      else 
      { 
       PopulateResponse("An error has occurred.", sElement, bEval) 
       //Coming soon, ajax call to php file to log javascript failure. 
      } 
     } 
    }); 
}  

这个CSS

div#dim 
{ 
    background-color:#000; 
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=60)"; 
    filter: alpha(opacity=60); 
    opacity:.6; 
    height:100%; 
    width:100%; 
    position:fixed; 
    top:0; 
    left:0; 
    z-index:1005; 
    display:none; 
    cursor:wait; 
} 

div#dim div 
{ 

    position:relative; 
    top:400px; 
    z-index:1006; 
    text-align:center; 
    cursor:wait; 
} 

div#dim div img 
{ 
    z-index:1007; 
    text-align:center; 
    border:none; 
    cursor:wait; 
} 

与此HTML

<div id='dim'><div style="text-align:center;"><img src="Images/Loading/loading10.gif" alt="Loading... please wait" title="Loading... please wait" /></div></div> 
相关问题