top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to receive JSON Data from server and display at the Client Side?

+1 vote
714 views
How to receive JSON Data from server and display at the Client Side?
posted Jul 18, 2017 by Ram Jana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

• JSON data is received as a string
• Calling eval() will generate JSON object in JavaScript code
var JSONdata = eval(req.responseText);
• Once you have JSON object, you can use . notation to access its properties
var name = JSONdata.name;
var address = JSONdata.addresses[3];
var streetname = JSONdata.addresses[3].street;

answer Jul 18, 2017 by Sumana
Similar Questions
+1 vote

Please help me with following -
1. Write a java program to get json data from URL http://echo.jsontest.com/Operand1/10/Operand2/5/Operator/+
2. Perform mathematical operation in java after reading JSON from above URL and print result.for ex.result=10+5=15
3. Result should be dynamic and should change if change values in above URL.

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 = 'http://127.0.0.1:5000/Get%20Form/';
  f.method = 'post';
  var i = d.createElement('input');
  i.type = 'hidden';
  i.name = 'url';
  i.value = tab.url;
  f.appendChild(i);
  d.body.appendChild(f);
  f.submit();   
});
$(".button").click(function(){
    request = new XMLHttpRequest();
    request.open("POST","http://127.0.0.1:5000/PutValue/",true);
    request.send();
    request.addEventListener("readystatechange", processRequest,false);
    function processRequest(e)
    {
    if(request.readyState==4 && request.status == 200)
    {
    var response = JSON.parse(request.responseText);
    a=response.result
    alert(a);
    }
    }
});
},false);

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__)
user=""
s=0

@app.route('/Get Form/',methods = ['POST'])
def GetForm():
request.method == 'POST'
url=request.form['url']
UrlTest.process_test_url(url,'test_features.csv')
s=ts.main_caller('url_features.csv','test_features.csv')
print s
return str(s)

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


if (__name__ == '__main__'):
app.run(debug=True,host='0.0.0.0', 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

...