I am trying to update values on my page when I user selects what they want to filter but I do not want to refresh the webpage constantly. As an example, think of a real estate website where you filter based on location and the types of housing e back with the number (e.g., apartment [4] townhouse [0] studio [5]). The types of housing will always be there but its the numbers I am interested in updating. When ever you change the filter, new numbers are popping up. What I am doing is filtering questions based on topic, subject etc.
Is there anyway to use this in node.js? What I have working so far requires the page to refresh.
$.ajax({
type="POST",
url: "/user/calculatequestions",
data: {
filter date here... },
success: function () { },
error: function () { }
});
The '/user/calculatequestions' goes through an app.post and renders a new page with new variables.
Thanks in advance, S
I am trying to update values on my page when I user selects what they want to filter but I do not want to refresh the webpage constantly. As an example, think of a real estate website where you filter based on location and the types of housing e back with the number (e.g., apartment [4] townhouse [0] studio [5]). The types of housing will always be there but its the numbers I am interested in updating. When ever you change the filter, new numbers are popping up. What I am doing is filtering questions based on topic, subject etc.
Is there anyway to use this in node.js? What I have working so far requires the page to refresh.
$.ajax({
type="POST",
url: "/user/calculatequestions",
data: {
filter date here... },
success: function () { },
error: function () { }
});
The '/user/calculatequestions' goes through an app.post and renders a new page with new variables.
Thanks in advance, S
Share Improve this question asked Sep 7, 2015 at 19:57 SzpokSzpok 631 gold badge1 silver badge9 bronze badges 4- why invoke a post if the user is only changing drop-downs et al? you should add an event-listener to your filter elements and when they click [apply], then you can invoke your ajax func. – Data Commented Sep 7, 2015 at 20:16
- thanks for the response. ideally I want the values to be updated as the user changes the checkboxes (i.e., filter) and I do not want to invoke a post. I just want to get something working and now am polishing it up a bit. My question is how do I send send filters to node and have node send back some numbers without having the refresh/post the page. – Szpok Commented Sep 7, 2015 at 20:38
- nothing in ajax code shown would refresh the page. Queston doesn't make sense – charlietfl Commented Sep 7, 2015 at 20:38
- Sorry. Please bear with me. I am using ajax to municate with the server. The server does a res.render which refreshes the page. My question is how would you send back data from node.js to the webpage without refreshing the webpage so I could update the values. I used res.render because that was the only way I could think of in my limited experience to get something working... – Szpok Commented Sep 7, 2015 at 20:55
1 Answer
Reset to default 3You can get the values of the filter through Java Script and send data filter through Ajax.
Example of input:
<input id="field" name="field1" type="text" >
Java Script function (together Ajax stack):
var data = {};
data.fielter_data1 = document.getElementById('field');
$.ajax({
type="POST",
url: "/user/calculatequestions",
data: data,
success: function () { },
error: function () { }
});
Then, in the function node called /user/calculatequestion you can get the parameters filter with:
var filter_data = req.body.fielter_data1;
The success callback returns the data after note proccess, then you update the ponents (inputs, tables, lists and etc) in the front-end.
See this question please: How to refresh table data using Ajax, Json and Node.js