2011-07-05 8 views
2

내 고전적인 ASP 응용 프로그램에서 ajax 호출을 사용하여 저장 프로 시저를 실행하고 있습니다.
그러나 저장 프로 시저가 실행될 때까지 기다리는 것을 원하지 않습니다 (완료하려면 약 5-10 분 정도 소요되는 저장 프로 시저).
Ajax는 저장 프로 시저를 호출해야하고 즉시 복귀해야합니다.
응답을 기다리지 말고 Ajax 호출을 원합니다. 다음은 내가 사용하고있는이 아약스 호출입니다Ajax 호출이 응답을 기다리지 않아야합니다.

1) $.ajax({ 
    type: "POST", 
    url: "runstoredprocedure.asp", 
});  
2) setInterval(function(){ jQuery("#list").trigger("reloadGrid"); },10000); 

:

여기 내 코드입니다. 첫 번째는 약 5-7 분 정도 작동합니다. 두 번째 것은 첫 번째 작업이 완료 될 때까지 실행되지 않습니다. 하지만 즉시 두 번째 아약스 전화를해야합니다.

누구든지이 문제에 대해 도움을 줄 수 있습니까?

답변

2

기본적으로 AJAX는 비동기입니다 (모든 자바 스크립트 라이브러리에서 기본 옵션입니다). 예를 들어, jQuery의 경우 :

$.ajax({ 
    url: url, 
    data: data, 
    success: success, 
    dataType: dataType 
}); 

성공한 경우 콜백을받습니다. 작업이 끝나면 콜백이 호출됩니다. jQuery가 즉시 반환됩니다.

+0

나는 $ 아약스를 falowing usingthe하고 ({ 유형 : "POST", URL : "P ... te.asp" }}); 하지만이 아약스 호출이 긴 시간 동안 실행되는 화재 버그를 발견했습니다. – vissu

+0

@vissu pepala, 질문을 수정하여 사용중인 코드 스 니펫을 추가하십시오. 댓글에서 볼 수 없습니다. – Senthess

+0

나는 편집했다. @Senthess, 당신은 지금 볼 수 있습니까? – vissu

3

자바 스크립트가 요청을 다른 스레드의 일부로 실행하면 아약스 호출에 이어지는 코드가 즉시 실행됩니다. JS 비동기에 대한 오해 한 가지가 있습니다.

People take for granted that because it’s asynchronous, it’s a thread. They are partially right. There must be a thread created by the browser to keep the javascript running while it makes a request to the server. It’s internal and you don’t have access to that thread. But, the callback function called when the server responds to the ajax request is not in a thread. 

I’ll explain clearer. If javascript runs some code that takes 5 seconds to execute and an ajax response arrives at 2 seconds, it will take 3 seconds before it will be executed (before the callback function is called). That’s because javascript itself doesn’t create a thread to execute the ajax response from the server and simply waits that all executions are terminated before starting a new one. 

So if you’re running a lot of ajax requests simultaneously, you might get some weird behavior because they will all wait one on another before executing themselves. 

마지막 문장은 귀하의 사유와 관련이 있습니다.

블로그에서 발췌 : http://www.javascriptkata.com/2007/06/04/ajax-and-javascript-dont-use-threads/

재미있는 읽기 : http://www.javascriptkata.com/2007/06/12/ajax-javascript-and-threads-the-final-truth/

관련 문제