2013-03-05 3 views
2

.each() 안에 비누 요청을하려고하지만 jQuery가 첫 번째 비누 요청이 완료되기 전에 목록의 다음 객체를 실행합니다. 어떻게 자물쇠를 걸 수 있습니까? 예를 들어각각을 결합하는 방법

:

당신은 SOAP 요청의 전체 콜백 함수의 내부는 $ .each 루프의 다음 반복을 실행해야
$(xmlHttpRequest.responseXML).find("Items").find("PowerPlant").each(function(index, item){  
    sendSOAPRequest(item); 
}); 
+1

그것은 콜백에 관하여 :이 작동하지 않습니다

$(xmlHttpRequest.responseXML).find("Items").find("PowerPlant").each(function(index, item){ sendSOAPRequest(item, {async: false}); //Might be other syntax. Look at the doc for your library. }); 

경우 브래드 M에서 알 수 있듯이, 당신은 할 수 있습니다. 'sendSOAPRequest()'를 보여줄 수 있습니까? – Marc

답변

2

어떤 라이브러리를 사용하고 있는지 확실하지 않지만 일부 버전에서는 sendSOAPRequest 호출 중 일부에서 async 변수를 false로 설정할 수 있어야하므로 한 번에 하나씩 실행해야합니다. :

items = $(xmlHttpRequest.responseXML).find("Items").find("PowerPlant");   

function sendSoapReq(itemList){ 
    if(itemList.length > 0) 
    { 
     sendSOAPRequest(itemList.splice(0,1), function(){ 
      sendSoapReq(itemList); 
     }); 
    } 
} 

sendSoapReq(items); 
+0

오 세상에 ... 부끄러운 줄 알아! $ .ajax & asyn 속성을 사용했습니다. ( 감사합니다. – RaspDealer

+1

요청을 동기식으로하면 브라우저가 "잠겨"일반적으로 바람직하지 않은 동작입니다. 비동기 및 콜백을 사용하는 것이 좋습니다. –

0

.