4

一般的な理解のための簡単な質問です。開いている Web ソケット接続が ajax リクエストをブロックしている可能性はありますか? Webソケット接続の初期化前のajaxリクエストは正常に機能し、Webソケット接続を確立した後は何も起こらないためです。

$.ajax({
   url: someUrl
}).done(function(data) {
    // stuff done and calling initWebSocket()
}).error(function(data) {
  // error stuff done
});

function initWebSocket() { 

    hostname = 'somehost';

    ws = new WebSocket('ws://' + hostname + ':' + wsPort);

    ws.onopen = function() {

    console.log('Connected');

    ws.send(initMessage);
}

ws.onmessage = function(msg) {

// do stuff on message received

}

ws.onclose = function() {
console.log('Disconnected');
}

}

$('#someButton').click(function(event) {

event.preventDefault();

$.ajax({
url: someUrl
}).done(function(data) {
console.log(data);
}).error(function(data) {
console.log(data);
});

});

前述のように、最初の ajax リクエストは機能しますが、ボタンをクリックしたときの 2 番目のリクエストは機能しません。このトピックに関する情報はありますか? Web ソケットが本当に ajax リクエストをブロックしている場合、それを実行するための回避策は何ですか? ありがとう。

4

1 に答える 1