简体   繁体   English

Socket.io客户端发出旧数据

[英]Socket.io Client emit old data

I want the button to emit only a new data. 我希望按钮仅发出新数据。

My button set on click with the function below, 点击下面的功能设置我的按钮,

function regis() {
  socket.emit('register', 
  {
    'username': $('#regis-username').val(), 
    'password': $('#regis-password').val(), 
    'email': $('#regis-email').val()
  },function () {
     console.log('Regis');
  });
}

When I click on it at first time, it emits my data to the server. 第一次单击时,它会将我的数据发送到服务器。 //This is correct. //这是对的。 So I try second time, it emits my old data to the server and emits my new data to the server. 因此,我尝试第二次,它将旧数据发送到服务器,并将新数据发送到服务器。 ( 2 times emit in order ) So I try third time, it emits my old data then my second data then my new data. (按顺序发出2次)所以我第三次尝试,它发出我的旧数据,然后是我的第二个数据,然后是新数据。 (3 times emit in order) (按顺序发出3次)

How can I do to make my button emit only one time with my new data for each click? 如何使按钮每次发出的新数据仅一次发出一次?

There's nothing in the code that I can see that would cause the client to emit more than once and anything but what is in those elements. 我看到的代码中没有什么会导致客户端发出不止一次的东西,除了那些元素中的东西。

Are there any other places with room for error? 还有其他可能出错的地方吗?
Maybe as a precaution you can clear the form elements? 也许作为预防措施,您可以清除表单元素?

function regis() {
    socket.emit('register', 
        {
            'username': $('#regis-username').val(), 
            'password': $('#regis-password').val(), 
            'email': $('#regis-email').val()
        },
    function () {
          console.log('Regis');
          $('#regis-username').val('');
          $('#regis-password').val('');
          $('#regis-email').val('');
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM