how to show a success message when ajax called successfully


BY LOVE,
1- "beforeSend" event used to execute something before ajax call
2- "complete" event used to execute something after the ajax called successfull.

$.ajax({
url: ' @Url.Action("AttendanceUpdateLate", "Attendance")',
data: { Emp: $("#txtEmpid").val(), Status: $("#ddlAttendance").val(), day: $("#ddlday").val(), Month: $("#Month").val() },
datatype: "json",
type: "POST",
contenttype: 'application/json; charset=utf-8',
async: true,
success: function (data) {
alert(data);
},
beforeSend: function () {
alert("Alert showing before AJAX call");

},
complete: function () {
alert("Alert showing after AJAX call successfully");
$("#txtEmpid").val('');
$("#ddlday").val('');
$("#ddlAttendance").val('');
},
error: function (xhr) {
alert('error occured');
}
});

www.codegrepper.com
www.stackoverflow.com

how to send message to specific client using ws node js


var Server = require('ws').Server;
var port = process.env.PORT || 9030;
var ws = new Server({port: port});

var sockets = [];
ws.on('connection', function(w){

var id = w.upgradeReq.headers['sec-websocket-key'];
console.log('New Connection id :: ', id);
w.send(id);
w.on('message', function(msg){
var id = w.upgradeReq.headers['sec-websocket-key'];
var message = JSON.parse(msg);

sockets[message.to].send(message.message);

console.log('Message on :: ', id);
console.log('On message :: ', msg);
});

w.on('close', function() {
var id = w.upgradeReq.headers['sec-websocket-key'];
console.log('Closing :: ', id);
});

sockets[id] = w;
});

www.codegrepper.com
www.stackoverflow.com

how to read if a person has send a message on discord.js


client.on('message', message => {
// this function can check whether the content of the message you pass is the same as this message
let filter = msg => {
return msg.content.toLowerCase() == message.content.toLowerCase() && // check if the content is the same (sort of)
msg.author == message.author; // check if the author is the same
}

message.channel.awaitMessages(filter, {
maxMatches: 1, // you only need that to happen once
time: 5 * 1000 // time is in milliseconds
}).then(collected => {
// this function will be called when a message matches you filter
}).catch(console.error);
});

www.codegrepper.com
www.stackoverflow.com