I'm new at web apps and at the moment I'm trying to wrap my head around routing from client side to server side and back. I ran in to a problem where I was doing xmlhttprequest on my client side to get a json, which was working. But now that im not running locally none of the GETS are working. So I figured I have to do routing to server side, do the request() to get the json, which I can.
But now what I don't understand is how to pass that json back to client side to use the function there, since all my functions that use this json are there. Is this possible? or do I have to do everything server side now?
server side
server.get('thankyou.html/something', function(req, res) {
var options = {
url: 'https://**.***.**.**:****/****/*******/',
rejectUnauthorized: false,
method: 'GET'
};
request(options, function (error, response, body) {
if (error) console.log(error);
else displaytable(body);//<------- clientside funtion
});
});
client side
var uri = 'thankyou.html/something';
function addTable() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status == 201 || xhr.status == 200)) {
// var json = JSON.parse(xhr.responseText);
displaytable(json);
}
};
xhr.open("GET", uri, true);
xhr.send();
}
I think I'm not doing the routing right either.