未捕获的引用错误:未定义 newMoney

金xxx

尽管我已经在顶部定义了 newMoney,但为什么没有定义,这是我的代码:

             var deduct = 100;
             var newMoney = {{user.e_money}} - deduct;
             var username = getUserName(); //get the current user
              // send a message to the server that the e-money value has changed
             socket.emit('update e-money', username, newMoney);

             console.log("Emitting the data to the server side - emoney: " + newMoney + " with the name money of : " + username);
            //end 

            clearTimeout(interval);
            //send the data to the server
            socket.emit('chat message', getUser());
            var interval = setTimeout(function(){
                $('.'+getUser()).fadeIn();
            },5000);
        });

             socket.on('update e-money response', function (data) {
             alert("Your money is: "+ data.newMoney);
             console.log("Your money is: "+ data.newMoney);
             });

在我的服务器端,这是我的代码:

 //emoney
socket.on('update e-money', function (data) {
 var userName = data.username;
 var newMoney = data.newMoney;
//var query = {"name": userName};

  // update the entry on the database
  User.findOneAndUpdate({"username":userName}, {"$set":{"e_money": "300" }}, { upsert: true, returnOriginal:false }, function (err, doc) {

if (err) {
  console.log("There was an error: " + err);
  console.log(userName);
  io.emit('update e-money error', { error: err });

} else {

    io.emit('update e-money response', { newMoney: newMoney });
    console.log(newMoney);
}
  });
  });

我不知道为什么它是 undefined 。你能帮帮我吗伙计们。任何人。

金xxx

问题就在这里

  var deduct = 100;
  var newMoney = {{user.e_money}} - deduct;
  var username = getUserName(); //get the current user
   // send a message to the server that the e-money value has changed
  socket.emit('update e-money', username, newMoney);

我应该这样做

  var deduct = 100;
  var newMoney = {{user.e_money}} - deduct;
  var username = getUserName();
  var compile = {newMoney, username};

然后在我的服务器端使用它:)

然后我会像这样发出它

 socket.emit('update e-money', compile);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Rails 6:未捕获的引用错误-未定义$

未捕获的引用错误:未定义$?

未捕获的引用错误:未定义tinymce

未捕获的引用错误需要未定义

未捕获的引用错误:未定义LocalFileSystem

未捕获的引用错误:未定义$(Reactjs)

未捕获的引用错误:未定义队列

未捕获的引用错误变量未定义

未捕获的引用错误:未定义 faceapi

未捕获的引用错误:在Request.request中未定义Jsonbody

尝试传递参数时未定义未捕获的引用错误 xyz

Java中未捕获的引用错误和未定义

无法从主体 onload 调用函数(未捕获的引用错误:resetLoginForm 未定义)javascript

引用错误:函数未定义

libssh 未定义引用错误

DataTables和Ajax使用错误“未捕获的TypeError:无法读取未定义的属性'length'”

我正在学习并尝试在控制台中打印这些函数,但总是告诉我未捕获的引用错误:未定义对象

声明变量时extern未定义引用错误

我的代码中的C ++未定义引用错误?

只有CascadeClassifier产生未定义的引用错误

静态constexpr数据成员的未定义引用错误

引用错误,表示未定义变量

如何解决“未定义的引用错误”?

从 makefile 中获取未定义的引用错误

无法解决未捕获的引用错误

错误错误:未捕获(承诺):TypeError:用户未定义

未捕获的参考错误:$未定义错误

通过结构的引用时出现未定义的引用错误

TypedJS错误:未捕获ReferenceError:未定义类型