export function ajax(url, method, data, success, error)
{
let xhr = new XMLHttpRequest();
- if (typeof(data) === "function") //no data
+ if (data === undefined || typeof(data) === "function") //no data
{
error = success;
success = data;
data = {};
}
+ if (!success)
+ success = () => {}; //by default, do nothing
if (!error)
error = errmsg => { alert(errmsg); };
-
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200)
{
"(" + Date.now() + "," + c.uid + "," + (!!c.to ? c.to + "," : "") +
c.vid + ",'" + c.fen + "','" + c.timeControl + "')";
db.run(query, err => {
- return cb(err);
+ return cb(err, {cid: this.lastID});
});
});
},
to: req.body.chall.to, //string: user name (may be empty)
};
const insertChallenge = () => {
- ChallengeModel.create(challenge, (err) => {
- if (!!err)
- return res.json(err);
+ ChallengeModel.create(challenge, (err,ret) => {
+ return res.json(err || {cid:ret.cid});
});
};
if (!!req.body.chall.to)