Hi I am using a form which takes input of some data and when I press submit an Ajax Post request goes to the server which then saves the data in the database and then data only gets updated on the ejs Page when I press refresh. I want to know is there any way I can make any call through either Jquery or JavaScript that on the success of AJAX POST re renders the ejs page and page is again functional without refreshing?
I tried to use the below code to re load the page what it does is; it works, reloads the data but that data is not accessible or its values are not usable until I refresh
The code I used
$('body').load('views/test.ejs', function () {
$(this).fadeIn(5000);
});
My rendering function looks like this;
function renderList(res, list) {
res.render('admin', {
jsonList: list, // JSON of data generated from DB
listId: req.session.user.listID, //global session
access: req.session.user.Access, //global session
products: req.session.user.Products, //global session
user: req.session.user.FirstName || req.session.LastName
});
}
I have a tabbable menu of bootstrap in which I am passing the IDs of the data from Databases and using those tabbable menu to display corresponding data of that item. So I am not getting IDs when I just use the Load function. only location.reload() works for me but its not a good way to do it.
jQuery .ajax() and .post() have success callback functions that you can use to update the page with your new data. Try looking at this answer of mine for an example.