Node.js/Express 4 - How to update a page to show progress in workflow - html

i built a small page to track a workflow with multiple steps. The page contains a form with submit button to start the flow. Each step sends back a status to the page. The page html is rerendered with res.render() then and sent to the server with res.send(html).
My problem now is, that when i use res.send(), the next status update gives a failure, because the response process is finished before.
Using res.write() instead crashes the page for whatever reason. I looks like the page is appended a second time (from a buffer??), instead of overwriting it.
Any ideas how to solve that??
Moe

Related

Getting a 302 in shell but not in browser

When I try to get a wget request of page 430 I get a redirect 302.
wget "https://www.zalando.be/kleding/?p=430"
results in
HTTP-verzoek is sent; waiting on answer... 302 Moved Temporarily
Location: /kleding/?p=429 [following...]
--2018-11-10 21:08:57-- https://www.zalando.be/kleding/?p=429
However, when I access the site and push on the button for next page, then it goes to "https://www.zalando.be/kleding/?p=430".
I don't understand how this is possible, can someone elaborate this for me?
Also is it possible to do this in the shell?
So it seems that accessing by either wget or directly writing in the browser's address bar the site's URL for p values greater than 429 will trigger a 302 redirect.
This doesn't happen while pressing the next button because in this way the page content is loaded through AJAX. This is an example of a request being made when clicking the next button: https://www.zalando.be/api/catalog/articles?categories=kleding&limit=84&offset=36036&sort=popularity
I suggest investigating the paging logic for some conditional that may trigger the redirect as an out of range page request protection.
I was wrong.
It seems that when reloading the page several times, the contents change. The fact that the browser also receives a 302 code when going to www.zalando.be/kleding/?p=430 means there is a server side "problem" with the dynamic content. I don't know how Zalando works, but my best guess is that the popularity sort throws the system off. When the system doesn't know the right amount of entries, it then redirects to page 429 (as evidenced by 431 also redirecting).
This is probably a very temporary redirect because I cannot reproduce the problem.

How to add an HTML button

I'm building a web app (well at least one page on it) that shows the results of pings to different IPs.
I have no probs on Go displaying them on an HTML page. The simple thing I can't do (and I read so many tuto/threads that I'm lost and don't know what to do....) is to create a button "Refresh" that could just call back the "pingip" function i created in Go file.
Anyone has a concrete/"easy" example on how I could do this?
Assuming you have a HTTP Handler for your Go program, which is what is serving the page - then you can have the button simply do a window.reload() through JavaScript, which will reload the page in the browser and re-invoke the Go script.
If you want this to happen without a reload, then you'd have to create a different HTTP Route and use AJAX (look up the fetch method in JavaScript), get the results over the network (maybe as JSON) and then update the data in the frontend.

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.
I have tried the following approaches -
Create a nocache function and call the decorator in the page function
I have tried putting headers in my HTML
Using Command + Shift + R in Chrome for MacOS for a "hard" refresh
No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.
Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!
EDIT:
I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.
I finally found another post on Stack Overflow regarding my question.
Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

html page refresh on server side event triggering

I have a folder where xml files are uploaded including livescore data for matches. I want every time an xml arrives, a php parser to be triggered, parse the data and refresh an html page on a browser displaying the livescore data. I can make the folder monitoring and php triggering but I am concerned on how to make the page refresh without the client request.
This can be accomplished using AJAX. If you're unfamiliar with the method, it involves using JavaScript to fetch data without refreshing the website.
Your problem could be solved by making an AJAX script that every few seconds requested new content from the webserver, e.g. using a call like /newdata.php?date=1321640052. The server then checks if there has been new data since 1321640052 (a UNIX timestamp of the last content refresh - or when the page was first loaded). If there has been, the page contains a value (yes) to indicate new data is available, and JavaScript refreshes the page. Alternatively, you could just dynamically update the content using AJAX after the call has been made.

Trigger a web page refresh

I am working on an android application that will show an html page that contains only some text on a tablet device. The device will be on and showing this page for long periods of time(several hours). The text on this page will get changed from time to time.
To change the text on the page I've made a separate second page that contains a form to enter the new strings into and a submit button that uses ASP to generate a new version of the first page and save it over top of the original copy. This is set up and working great, but it means that I have to refresh the page very frequently in order to ensure I am always showing the latest message.
I am looking for a way that I could trigger a refresh only when a new message is saved. That way I will not have to refresh the page every minute but the new message will still get shown in a timely manner.
No dice, HTTP is built as a stateless, pull-only (ignoring file uploads) protocol. The server can't push data to the client, the client has to actually poll the server for new information.
However, you can minimize the overhead of this by using an AJAX call with JSON as the transport protocol instead of generating entire web pages and update your page on the client side. The overhead should be minimal for almost any application.
If you were just a web-app, I would suggest looking into the various Comet frameworks.
http://www.google.com/search?q=comet+framework
But, since you have an Android shell around it, you can make a Socket connection back to your server and have the server signal when it's time to refresh. It's essentially the same, but you don't need to code up the push in JavaScript if you're more comfortable in Java.