Custom plugin: Which is better jQuery post Or socket.emit and Why?
-
I want to clarify which approach shall I use to send the data from the client to the server. The jQuery post method or socket.emit?
My client side js
var userData = { location: markerLocation }; socket.emit('userData.save', userData, function (err, data) { if (err) { return app.alertError(err.message); } app.alertSuccess('[[map:details_save_success]]'); });
My plugin controller.js
Pl. help me write this piece of code: Shall I use socket.on or some other socketAPI? Also pl. guide me the right approach to overwrite the existing data (if any) for this particular req.uid in Mongo DB
Thanks in anticipation
-
You can do it either way. If you know how to handle posts then I'd suggest doing that. Otherwise, there are examples of socket usage in various plugins.
Copyright © 2024 NodeBB | Contributors