2011-07-05 10 views
2

私は古典的なaspアプリケーションでajax呼び出しを使用してストアドプロシージャを実行しています。
しかし、ストアドプロシージャが実行されるまで待つ必要はありません(ストアドプロシージャは約5〜10分かかります)。
Ajaxはストアドプロシージャを呼び出す必要があり、すぐに戻ってくる必要があります。
私はAjaxコールが応答を待つべきではないことを望みます。これらは私が使用しています2つのAJAX呼び出しですAjax呼び出しは応答を待つべきではありません

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

は、ここに私のコードスニペットです。最初のものは約5-7分走っています。第2のものは、最初のものが完了するまで発射されない。しかし、すぐに私は2番目のajax呼び出しを呼び出す必要があります。

誰でもこの問題について私を助けることができます。

答えて

2

デフォルトでは、AJAXは非同期です(これはすべてのjavascriptライブラリのデフォルトオプションです)。たとえば、jQueryの場合:

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

あなたは成功しており、コールバックを受け取ります。アクションが終了すると、コールバックが呼び出されます。 jQueryはすぐに戻ります。

+0

私は$アヤックスをfalowing usingtheています({ タイプ: "POST"、 URL: "P ... te.asp"、 });しかし、私は長い時間のために実行されている火災のバグを使用して、このAJAX呼び出しが見つかりました。 – vissu

+0

@vissu pepala、質問を編集して、使用しているコードスニペットを追加してください。コメントからは見えません。 – Senthess

+0

私は編集しました。 @Senthess、あなたは今見ることができますか? – vissu

3

javascriptは要求を別のスレッドの一部として起動し、あなたのajax呼び出しに続くコードは直ちに実行されます。 JS asyncについての誤解が1つあります。

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/