node.js - Send a POST when the user hits the bottom? -
there loads of questions have same problem, ones i've found tell how actual javascript works, not routing kind of thing.
so i'm bit lost @ moment trying implement html , routing side of infinite scroll system using node.js, express, , mongodb.
i know how checks when user hits bottom, , know need have kind of listener in app.post route tell database append data. don't know doing 'posting', , how should route it.
is onclick listener watching "submit" value true? , when user hits bottom, becomes true, express gets post, loads ten more entries.
i literally don't understand actual concept of waiting event value in routing file, thought whole point of separating front , end meant not wait value "true" in javascript , return that.
this pretty general question think, , code not needed.
so if give decently broad explanation of how should looking @ whole event listening thing , routing it, lot. seems impossible.
"what doing 'posting'"
when form gets submitted, it's 'posting'. "submit" action, function call, not boolean value being watched true or false.
<form method="post" action="/url"> <input name="name" value="value"> <button>submit</button> </form>
here when button clicked, post request fired off server.
app.post('/url', function(res, res, next){ req.body //=> {name: 'value'} });
is onclick listener watching "submit" value true?
an onclick
event event. listener function, attached it, fired when event occurs.
<button onclick="fn()"> call `fn();` </button>
function fn(){ console.log('that button pressed'); }
there many such events. 1 may using onscroll
, fires when page scrolled. it's sensitive event , fires smallest of fluctuations in scroll positions. may reason form being posted many times @ once.
so can stick function
example()
routing/server file, , use<button onclick="example()">call 'example()';</button>
, codeexample()
db.collection.find().limit(10)
make possible push database requests around?
no, you're mixing client-side , server-side code.
html elements, <button>
, , javascript associated them, onclick
events, reside on client-side, on browser.
you server-side code, nodejs, can interacted or respond client through http requests, get /
, post /form
.
what need ajax, using client-side javascript make , handle result of above mentioned requests made server.
Comments
Post a Comment