socket.io变量检查
好吧,基本上我在 ajax 中有一个变量,我想将其发送到我的 socket.io 服务器以检查该变量是否已经在 json 数组中。
Ajax:
function isUniqueEmail(email) {
//email checking script here
$.get('info/mailcheck.js' + email, function(response) {
if(response == 1) {
alert("Your email is already on our list");
}
else {
alert("We will add you shortly");
};
})
};
json 数组:
{"mail":
[
"[email protected]",
"[email protected]",
"[email protected]"
]}
socket.io 部分是我感到困惑的地方。基本上它只需要获取变量(一封电子邮件)检查它是否已经在数组中,如果是则返回 1,如果不是则返回 0 并将其写入数组中。
Okay so basically I have a variable in ajax which I want to send to my socket.io server to check if the variable is already in a json array.
Ajax:
function isUniqueEmail(email) {
//email checking script here
$.get('info/mailcheck.js' + email, function(response) {
if(response == 1) {
alert("Your email is already on our list");
}
else {
alert("We will add you shortly");
};
})
};
the json array:
{"mail":
[
"[email protected]",
"[email protected]",
"[email protected]"
]}
The socket.io part is where im confused. Basically it just needs to take the variable (an email) check if it is already in the array and return a 1 if it is or return a zero if not and write it in the array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 node.js 不太了解,但您可以使用类似于以下的函数来检查值是否在数组中,如果不是,则将值推送到数组中。
I don't know much about node.js but you could use a function a bit like the following to check if a value is in an array and push the value to it if it is not.
您是否对如何使其与 socket.io 一起使用或如何查找数组中的元素感到困惑?如果您使用的是node.js,只需使用array.indexOf方法:
Are you confused about how to get this to work with socket.io or just how to find the element in the array? If you're using node.js, just use the array.indexOf method: