I want to render a page (output.ejs) and then download that same page all with one button click. In my POST method I redirect to "/output" where the GET request renders output.ejs. However I cannot call res.download("") after that render (something to do with it being asynchronous). What's the best way at tackling this. BTW I am using wkhtmltopdf as PDF generation which needs to happen AFTER the page gets rendered since I am sending data to it.
Best
Try res.render('/output').download()
Related
I'm adding new data to database
but to load the new data I have to reload the page
I was wondering is there anyway to reload a loaded page without refreshing the
whole page ?
P.S : I have used the .html thing and it won't load new data
$(document).ready(function () {
$(".container").load("../../public/include/menu/add.php");
$("#add_from").ajaxForm(function () {
$(".container").reload("../../public/include/menu/add.php");
});
You may be overthinking this. Consider how you load your data from the server:
$(".container").load("../../public/include/menu/add.php");
Now, at a later time in the page, you wish to load your data from the server. You would just repeat the process:
$(".container").load("../../public/include/menu/add.php");
You're trying to repeat an action at a later time, you would do so by calling the same code again. You can encapsulate it in a function if you don't want to duplicate the code, but overall you just repeat the process any time you want to repeat the results.
Though it's not really clear what you mean by "used the .html thing". And this probably isn't the most performant approach, as you could likely return updated data directly to the AJAX form post instead of requiring another request entirely. But if this is easier for you, go for it.
If your default data is being fetched with ajax, you probably just need to call the fetch method. You can use location.reload() instead, if you aren't fetching with ajax.
I have a table with live data in it (meaning it is stored on the server and people who has access can view the data in their machine as well). I have a Create data page and View data page that contains the table. Once I have finished creating a new data and click a link going to the View page. The data should be there already.
I have tried the location.load() internal script in the View.html page that is triggered by the attribute onLoad="" but it's not working. However, when I create a button that has a function to refresh, it does work but I want it to be an auto refresh.
To make it easy and simple, use location.reload(). You can also use location.reload(true) if you want to grab something from the server.
You can simply use an jQuery Ajax call to make call to your backend API and fetch data, which you can add to your html table. This process you can handle in page/document ready or load events. I don't think you need to reload the page just to achieve this.
If you are working with AngularJs SPA (mentioning this as you added the tag), these two HTMLs/Pages can be rendered into the same layout based on the route and follow the above mentioned approach (using $http.get of Angular) to get view data and bind it to the respective view. As it is SPA, no concept of page reload.
I am trying to figure a way to render a webshot view of another page in my project without actually having to visit said page. The end goal should be taking a webshot of the page and returning it as a pdf to the client. Currently I have a view button, which will dynamically render a styled HTML page with relevant data in a new window at a specified URL(this is what needs to become a pdf).
Using webshot, would I be able to just specify the URL that renders the page and then take a webshot? Or will i have to look at using SSR methods to render the page on server side and webshot that result?
when I do the webshot of the URL that should render the page, All that is returned is a blank PDF. Is webshot even possible to use on localhost pages? If I were to webshot "www.google.com" I am returned a view of google.com, so the webshot code works, just not at the local URL I need. Where am i going wrong? I am new to using webshot.
Thank you
I am using GET and POST methods for getting data from the server and getting response using request.send(object);.
However my requirements changed, I need to use request.render('pageName',object); but the render method refreshes my page but I only want to refresh a particular <div> section. I read on this link https://www.npmjs.com/package/ejs but I am not able to refresh only particular section without refreshing the entire page.
If you want to redraw only a part of the page then you probably need some kind of client-side rendering for your templates. You fetch the data from the server using GET just like you mentioned and then do the actual drawing of the page on the client instead of sending HTML with request.render.
Is there any way to show a loading element when user click on a link or any thing that cause page start to reload , until browser start to show server response?
you have to write a JavaScript function that shows the element that contains your loading mock up when you click let's say a button.
The page render will override that as soon as the server response back.
if you are familiar with JQuery and Ajax the best way would be to use an asyn post.
Use Jquery to show the loading mock up
Async post to the server
Use Jquery to get the response,hide the loading mock up, refresh the portion of the page you need to