왜 내 onbeforeunload가 이전에 있었을 때 실행되지 않습니까? 아니면 두 번째 동일한 명령에서 Ajax가 실패합니까?

StackOverflow https://stackoverflow.com/questions/564676

  •  05-09-2019
  •  | 
  •  

문제

이것은 이어집니다 이것 의문

이것 ~였다 일하고 있는:

<body onbeforeunload=
 "ajaxRequest('UnlockQuery.ashx?QueryID=266&UserID=11631');"> 

이것은 ASPX 페이지에서 다음을 사용하여 생성되었습니다.

<body onbeforeunload=
 "ajaxRequest('UnlockQuery.ashx?QueryID=<%= Session["QueryId"] %>&
 UserID=<%= Session["UserID"] %>')">

이것은 ~ 아니다 일하고 있는:

<body id="uxBodyTag" onbeforeunload=
 "ajaxRequest('UnlockQuery.ashx?QueryID=266&amp;UserID=11631');"> 

이것은 다음을 사용하여 작성됩니다.

uxBodyTag.Attributes["onbeforeunload"] += 
 "ajaxRequest('UnlockQuery.ashx?QueryID=" + 
 queryId.ToString() + "&UserID=" + Session["UserID"].ToString() + "');";

호출되는 코드는 이것입니다.

function ajaxRequest(url)
{
    xmlhttp=null;
    if (window.XMLHttpRequest)
    {   // code for all new browsers
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {   // code for IE5 and IE6
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp!=null)
    {
        xmlhttp.onreadystatechange=null;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
}

편집하다:

후속 호출이 동일한 잠금 해제로 이루어질 때만 실패하는 것으로 보입니다. 나는 이것이 Ajax 문제 일 수 있다고 생각한다 ....

도움이 되었습니까?

해결책

첨가

&date=DateTime.now.Ticks.ToString()

그것을 고쳐진 것 같습니다. 동일한 Ajax 호출이 들어오고 이전이 "해결"되지 않았을 때 IE7이 좋아한다고 생각하지 않습니다 (Ajax 통화가 반환되기 전에 페이지가 폐기됩니다).

도움을 준 모든 덕분에 감사합니다.

다른 팁

디버깅 수단을 위해 다음을 시도했습니다.

alert(url);
xmlhttp.open("GET",url,true);

예상 결과를 제공했습니다.

UnlockQuery.ashx?QueryID=319&UserID=11648

이제 서버가 무엇을 말하는지 확인할 수 있습니다.

xmlhttp.onreadystatechange = function() { 
  if (this.readyState == 4) alert(this.status + ": " + this.StatusText); 
};

편집하다:

결과적으로 브라우저 캐시는 예상치 못한 결과의 이유였습니다. 적절한 HTTP 헤더를 통해 Ajax 페이지를 캐싱하는 것이 좋습니다 (Pragma, Cache-Control, Expires).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top