문제

아래 코드를 고려하십시오.

this.usedIds = 0;

this.SendData = function(data)
{
    var id = this.usedIds;
    this.usedIds++;

    this.xmlHttpThing.open("POST", "/Upload.aspx", true);
    this.xmlHttpThing.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    var currentObject = this;
    this.xmlHttpThing.onreadystatechange = function() { currentObject.UploadComplete(id) };
    this.xmlHttpThing.send(data);
};
this.UploadComplete = function(id)
{
    if (this.xmlHttpThing.readyState == 4)
    {
        //First time id is 0
        //Second time id is 0                 <<<--------- Why??
        //Third time id is 1
        //Fourth time id is 2
        //Fifth time id is 3 ....         

        this.SendData("blabla");
    }
};

Anonymus 함수로 전달 된 ID가 첫 번째 호출 후 한 번의 전화로 지연되는 이유는 무엇입니까?

Firefox에서만 이런 식으로 보이는 것처럼 보이며, 즉 업로드 컴퓨터는 올바른 순서로 ID를 수신합니다.

두 번째 루프에서는 Send (Data)-라인에서 디버거를 중지하고 ID가 실제로 1임을 확인할 수 있지만 업로드 컴퓨터에 도달하면 그 인수에서 0으로 밝혀졌습니다.

편집 : 찾은 솔루션 :Firebug에서 콘솔 로깅을 비활성화하십시오.

도움이 되었습니까?

해결책 2

Firebug에서 콘솔 로깅을 비활성화하면 문제가 해결되었습니다!

다른 팁

나는 과거에도 같은 문제가있었습니다. 나는 그 원인을 정확히 기억하지 못하지만 증분을 응답 핸들러로 이동시켜 고정했습니다.

this.UploadComplete = function(id)
{
    if (this.xmlHttpThing.readyState == 4)
    {      
        this.usedIDs++;
        this.SendData("blabla");
    }
};

편집 : 그것에 대해 생각한 후, 나의 사례는 당신과 다를 수 있습니다. 왜 증가하지 마십시오 this.usedIDs 할당 할 때 id?

var id = this.usedIDs++;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top