简体   繁体   English

在“花式框”叠加按钮上单击时,Ajax无法按预期工作

[英]Ajax not working as expected when called on the Fancy Box overlay button click

I have silly question regarding Ajax and fancy box.i'm new to Ajax. 我对Ajax和花哨的盒子有个愚蠢的问题。 i'm using fancy box in one of my pages, as fancy box does on click of a button it pops up a form which has some input fields and button. 我在我的页面之一中使用了花式框,因为花式框在单击按钮时会弹出一个包含一些输入字段和按钮的表单。 On click of the button, tried to make an ajax call which needed to show an indicator until the call is complete.I made a synchronous call but the indicator did'nt show up, but the moment i made it an asynchronous call it displayed correctly. 在单击按钮时,尝试进行一个ajax调用,该调用需要显示一个指示器,直到调用完成。我进行了同步调用,但指示器没有显示,但是当我进行异步调用时,它显示正确。 Can any one explain the reason 谁能解释一下原因

Update: Have a look at the below code....it works fine and displays the indicator until we get a response from server...But the function when called on click of a button on the fancy box overlay does'nt work with async false isAsync is False 更新:请看下面的代码...。它可以正常工作并显示指示符,直到我们从服务器获得响应为止...但是当单击精美框上的按钮时调用该功能无法正常工作async false isAsync为False

function LoadCarrier(isAsync)
{
   try
  {
    SetCarrierLoadingIndicator("","Loading..");
    xmlHTTPObject1 = GetXMLHTTPObject();
    xmlHTTPObject1.onreadystatechange = OnPopulateCarrierComplete;
    var currentTime = new Date();
    var  parameters =   "";
    var pageNumber=document.getElementById(hdnCarrierCurrentPage).value;
    parameters += "CarrierPage";
    parameters += "^" + pageNumber;
    parameters += "~NetworkIds";
    parameters += "^" + GetAllSelectedNetworks();
    parameters += "~SelectedCarriers";
    parameters += "^" + GetAllSelectedCarriers();
    var parms = "?OPCode=LoadCarrier&Parms=" + parameters + "&RequestTime" + currentTime;
    var ajaxURL = ajaxCallHandlerUrl + parms;
    xmlHTTPObject1.open ("GET", ajaxURL, isAsync);
    xmlHTTPObject1.send(null);
}
catch(exception)
{
    alert(exception);
}
return false;

} }

     function OnPopulateCarrierComplete()
    {
     if (xmlHTTPObject1.readyState == 4)
   {
   var result = xmlHTTPObject1.responseText;
   var contents = result.split("[6CE650P$0$NTS3E!]");

   if (contents[0] == "SUCCESS")
   {
        SetCarrierLoadingIndicator("none","");
        if(contents[1].length > 0)
        {
            var details=contents[1].split("[$sEpaRaToR$]");
            document.getElementById(lblCarrier).innerHTML=details[0];
            document.getElementById(lblCarrierPaging).innerHTML=details[1];
            document.getElementById(lblCarrierCount).innerHTML=details[2];
            var tmp=details[3].split(',');
            for(var i=0;i<tmp.length;i++)
            {   
                CarrierList.push(Number(tmp[i]));     
            }
        }
        else
        {
            document.getElementById(lblCarrier).innerHTML="";
            document.getElementById(lblCarrierPaging).innerHTML="";
            document.getElementById(lblCarrierCount).innerHTML="0";
        }
   }
   else
   {
       if(contents[1] == "Session Expired")
       {
            parent.document.location = "Default.aspx";
       }
       else
       {
            alert(contents[1]);
       }
   }
}

} }

A synchronous call locks the browser from doing anything until the call is complete, whereas an asynchronous call allows other operations (such as indicator showing) to perform while it's waiting for the results to be returned form your server. 同步调用使浏览器无法执行任何操作,直到调用完成为止;而异步调用则允许其他操作(例如指示符显示)在等待服务器返回结果时执行。 So, when you make a synchronous call, the browser will not show your indicator, or do anything else, until it gets a response back from your server. 因此,当您进行同步调用时,浏览器将不会显示您的指示符或执行其他任何操作,直到从服务器返回响应。

In short, you should rarely need to make synchronous calls to your server. 简而言之,您几乎不需要对服务器进行同步调用。 The "A" in AJAX stands for "Asynchronous" for a reason :). 由于某种原因,AJAX中的“ A”代表“异步” :)。

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

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