在websocket编程中,我得到了iswebsocketrequest false的值 [英] In websocket programming I am getting the value of iswebsocketrequest false

查看:282
本文介绍了在websocket编程中,我得到了iswebsocketrequest false的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在websocket编程中,我得到IsWebSocketRequest的值为false。我想知道它为什么返回值false。

这是我的JavaScript代码。



我的尝试:



$('#openButton')。点击(功能(){



试试{



username = $('#txtuserid')。val();

var url =ws://+ window.location.host +'/ api /值?userid ='+ username;

demoService = new WebSocket(url);

console.log(url);

demoService.onopen = function(){

$('#divmsg')。append('Connection Opened
');

}



demoService.onmessage = function(message){

var md = message.data;

if(md.substring(0,5)= ='user:'){

$('#txloginuser')。val(md.replace('user:',''));

}否则if (md.substring(0,4)=='key:'){

$('#txuserkey')。val (md.replace('key:',''));

} else {

$('#divmsg')。append(message.data +< br>);

}

}



demoService.onclose = function(){

尝试{

$('#divmsg')。append(Connection Closed+
);

$('#txloginuser ')。val('');

$('#txuserkey')。val('');

$('#txuserid')。val(' ');

$('#divmsg')。empty();

} catch(ex){

alert(ex);

}

}





demoService.onerror = function(error) {

$('#divmsg')。append(error.data +
);

}

} catch( ex){

alert(ex);

}

});

In websocket programming I am getting the value of IsWebSocketRequest false. I want to know why it is returning value false. ‍ ‍ ‍
Here's my JavaScript code.

What I have tried:

$('#openButton').click(function() {

try {

username = $('#txtuserid').val();
var url = "ws://" + window.location.host + '/api/Values?userid=' + username;
demoService = new WebSocket(url);
console.log(url);
demoService.onopen = function() {
$('#divmsg').append('Connection Opened
');
}

demoService.onmessage = function(message) {
var md = message.data;
if (md.substring(0, 5) == 'user:') {
$('#txloginuser').val(md.replace('user:', ''));
} else if (md.substring(0, 4) == 'key:') {
$('#txuserkey').val(md.replace('key:', ''));
} else {
$('#divmsg').append(message.data + "
");
}
}

demoService.onclose = function() {
try {
$('#divmsg').append("Connection Closed" + "
");
$('#txloginuser').val('');
$('#txuserkey').val('');
$('#txuserid').val('');
$('#divmsg').empty();
} catch (ex) {
alert(ex);
}
}


demoService.onerror = function(error) {
$('#divmsg').append(error.data + "
");
}
} catch (ex) {
alert(ex);
}
});

解决方案

('#openButton')。点击(function(){



试试{



username =
('#openButton').click(function() {

try {

username =


('#txtuserid')。val();

var url =ws:// + window.location.host +'/ api / Values?userid ='+ username;

demoService = new WebSocket(url);

console.log(url);

demoService.onopen = function(){
('#txtuserid').val();
var url = "ws://" + window.location.host + '/api/Values?userid=' + username;
demoService = new WebSocket(url);
console.log(url);
demoService.onopen = function() {


('#divmsg')。append('Connection Opened
'); < br $>
}



demoService.onmessage = function(message){

var md = message.data;

if(md.substring(0,5)=='user:'){
('#divmsg').append('Connection Opened
');
}

demoService.onmessage = function(message) {
var md = message.data;
if (md.substring(0, 5) == 'user:') {


这篇关于在websocket编程中,我得到了iswebsocketrequest false的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆