Monday, 24 April 2017

dynamic data display in frontend from nodejs

I am very new to nodejs and web application development. I am running a python code inside nodejs. I just want to send the status of the code (i.e. running or finished or error) to be displayed in frontend in 2nd column of table. Here is my backend function (server.js)

app.post('/execute', function(request, response){
response.setHeader('Connection', 'Transfer-Encoding'); 
response.setHeader('Content-Type', 'text/html; charset=utf-8');
response.write("running");
console.log("running")
var pyshell = new PythonShell('./python_codes/test.py')
pyshell.on('message', function (message) {console.log(message);});
pyshell.end(function (err) {if (err){throw err;};console.log('finished');
response.write("finished");
response.end();});
});

my index.html file is

<html>
<body>
<table width="100%" bgcolor="#b5dcb3" border="2">
<tr> 
                                                
<td>
<form method="post" action="/execute" enctype="multipart/form-data">
<button id="execute" class="execute">execute</button>
</form>
</td>
<td>
<p>value to be displayed here</p>
</td>



</tr> 
</table>
</body>
</html>

on clicking execute button it should remain in same page but only its status to be displayed in 2nd column. Any small help will be highly appreciated.



via nishant kumar

No comments:

Post a Comment