user1816679
user1816679

Reputation: 855

Pulling a variable set on the front end to a node backend

I'm writing a comments section and the front end of my web app has information about what level of threading each comment is in. I need to pass this information to the back end when comments are submitted so that I can assemble all the threads and order them in node and then pass them back to the front end.

Right now the information is stored as a variable in the script.js file, though it could also be added as a class to the form that the user submits comments with. Is one of these methods considered to be better form?

So this is the comment reply form in html, after converting it from jade:

<form id="commentReply" class="sbBox jEgC97D 2" action="/comment" method="post" style="display: block;">
<h1>Post a Comment</h1>
<textarea name="comment" type="text" style="height: 349px;"></textarea>
<input type="submit" value="Post">
</form>

class="sbBox jEgC97D 2" is what I want. How do I get that into node so I can process it?

Upvotes: 0

Views: 869

Answers (1)

mithun_daa
mithun_daa

Reputation: 4384

The two options you have are:

  1. Sending the extra info (thread level) as part of you form post.
  2. Fire up another ajax request to send this info.

Option 1 makes sense because it would be efficient - 1 trip to the server and presumably 1 trip to the database - if you are storing all this in the database.

Option 2 would work out very expensive and a very inefficient way of doing things. You make 1 server call (you ajax request) and then have an additional call to go update the database for the appropriate comment.

Upvotes: 1

Related Questions