내 문제는 다음과 같습니다. 생성자에 새로운 XMLHttpRequest 객체를 생성하는 클래스 AJAXEngine을 작성했습니다. 이 클래스에는 responseAnalyser라는 메서드가 포함되어 있으며이 메서드는 XMLHttpRequest 객체의 "onreadystatechange"가 변경 될 때 호출됩니다. 그래서 이제는 AJAXEngine의 인스턴스 4 개 => 4 개의 XMLHttpRequest 객체를 만들 수있게되었습니다.여러 AJAX 요청으로 인종 상황
이제는 AJAXEngine의 인스턴스를 보유하고있는 배열 속성 dataReq가있는 다른 클래스 인 DataRequester가 있습니다. 전체 프로그램에는 DataReqeuster 인스턴스가 하나만 있습니다! DataRequester에는 callWhenFinished라는 함수가 있습니다. 이 함수는 AJAXEngine의 responseAnalyser 함수에 의해 호출되고 DataRequester 인스턴스의 변수를 감소시킵니다.
하지만 경기 상황이 발생했다고 생각합니다. JavaScript로 어떻게 그들을 prefent 수 있습니까? 모든
function AJAXEngine
{
this.httpReqObj = //create new XMLHttpRequest Object
this.obj;
this.func;
}
AJAXEngine.prototype.responseAnalyser = function()
{
if(this.httpReqObj.readState == 4)
{
this.func.call(this.obj);
}
}
AJAXEngine.prototype.fireReq = function(o, f)
{
this.obj = o;
this.func = f;
// fire ajax req
}
function DataRequester()
{
this.dataReq = new Array();
this.test = 4;
for(var i = 0; i < 4; i ++)
{
this.dataReq[i] = new AJAXEngine();
}
}
DataRequester.prototype.callWhenFinished = function()
{
this.test --;
}
내가 소스를 찾을 수있는 링크를 내게 줄 수 있습니까? –
링크가 답변에 있습니다 - 문제가 있습니까? 여기에 마크 업이 없습니다 : http://www.depressedpress.com/Content/Development/JavaScript/Extensions/DP_RequestPool/Index.cfm 다운로드 링크는 페이지의 첫 번째 섹션에 있습니다. –
안녕하세요, 예. 문제가 있습니다. 링크를 클릭 할 때마다 "요청 처리 중 오류가 발생했습니다"라는 제목의 파란색 상자가 나타납니다. 요소 DP는 클래스 유형 [Ljava.lang.String; –