top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to Send response from Python Server to JavaScript client

0 votes

i want to sent a response for my form submit from server to client, that means python flask to javascript. My javascript code is given follows

document.addEventListener('DOMContentLoaded', function() {

chrome.tabs.getSelected(null, function(tab) {
  d = document;
  var f = d.createElement('form');
  f.action = '';
  f.method = 'post';
  var i = d.createElement('input');
  i.type = 'hidden'; = 'url';
  i.value = tab.url;
    request = new XMLHttpRequest();"POST","",true);
    request.addEventListener("readystatechange", processRequest,false);
    function processRequest(e)
    if(request.readyState==4 && request.status == 200)
    var response = JSON.parse(request.responseText);

And my Python server code is follows

from flask import Flask, flash, redirect, url_for, request, render_template,jsonify
import json
import UrlTest
import trainingSet as ts

app = Flask(__name__)

@app.route('/Get Form/',methods = ['POST'])
def GetForm():
request.method == 'POST'
print s
return str(s)

@app.route('/PutValue/',methods = ['POST'])
def PutValue():
request.method == 'POST'
print s
return jsonify(result=s)

if (__name__ == '__main__'):,host='', use_reloader=False)

I want to send the value of s to the javascript client. please help me to send this the value of s.
and if u can suggest the complete code in javascipt and python

posted Sep 28, 2017 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

I am Getting may JSON array . But i can't know how to fill dropdown list with this array ...

  function Customer_Id()  
      var Cus_id = document.getElementById("customer").value;  
      var xhr;  
      if (window.XMLHttpRequest) // Mozilla, Safari, ... 
            xhr = new XMLHttpRequest();  
        else if (window.ActiveXObject) // IE 8 and older 
            xhr = new ActiveXObject("Microsoft.XMLHTTP");  
          var data = "Customer_ID=" + Cus_id;  

   "POST", "Volumne_WebUser.php", true);   
             xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                    
              xhr.onreadystatechange = display_data;  
      function display_data() {  
     if (xhr.readyState == 4) {  
      if (xhr.status == 200) {  
      var response = xhr.responseText;
      var obj = JSON.parse(response);
      } else {  
        alert('There was a problem with the request.');          
+1 vote

I would like to create a web app using flask or cgi library (python) along with telnetlib to telnet to specific servers and execute commands and retrieve the output. The output will then be formatted and outputted to a webpage .

Is this the best way of getting info from a remote system to be output to a web page? Is flask over kill for project like this ?

+1 vote

Write a function which can take a random JSON and transform the data into multiple line human readable title value pairs.

For example:

Given JSON

        university: 'Oxford',
        batch: '2019-2020',
        address: {
            street: '144 Main',
            city: 'London',
            country: 'UK',
            contact: {
                fax: 'XXXXXX',
                phone: 'YYYYY'
        students: [{
            name: 'Jon Doe',
            age: '22'
            name: 'Mike Wilson',
            age: '32'
            name: 'David',
            age: '28'


university: Oxford
batch: 2019-2020
address street: 144 Main
address city: London
address country: UK
address contact fax: XXXXXX
address contact phone: YYYYY
students 1 name: Jon Doe
students 1 age: 22
students 2 name: Mike Wilson
students 2 age: 32
students 3 name: David
students 3 name: 28
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.