Moving REST to server side
Permalink
Hi,
Right now I have HTML blocks that involve a script to call data from another DB (outside of concrete5) and I've been using XHTTP Posts to retrieve the data.
The problem:
The scripts currently exist on the client side (e.g. you can see it by inspecting element) and I think it is being called from the client's device. Once I close down access to that external DB, this won't work anymore.
The need:
I know there is a way to move these requests to within Concrete5, so that concrete5 is making the requests and not the client. I'm just not sure how to go about doing this. Any advice would be really appreciated.
[code]
<div some HTML Block that needs a value>
<script type="text/javascript">
// Global Var to store the value from the external DB
var amount = 0;
// need to move this part to within C5
// Open a new HTTP Request)
var xhr = new XMLHttpRequest();
xhr.open("GET", "Some_ElasticSearch Server", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var person = JSON.parse(xhr.responseText);
amount = person._source.age; // Grabs the person age // changes the value I ne
$('#chart_328').data('updateto', amount); //updates the above HTML data value
document.getElementById('chart_328_text').innerHTML = amount + '%';
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
///END PART TO MOVE///
// Some other functions to update the block///
Right now I have HTML blocks that involve a script to call data from another DB (outside of concrete5) and I've been using XHTTP Posts to retrieve the data.
The problem:
The scripts currently exist on the client side (e.g. you can see it by inspecting element) and I think it is being called from the client's device. Once I close down access to that external DB, this won't work anymore.
The need:
I know there is a way to move these requests to within Concrete5, so that concrete5 is making the requests and not the client. I'm just not sure how to go about doing this. Any advice would be really appreciated.
[code]
<div some HTML Block that needs a value>
<script type="text/javascript">
// Global Var to store the value from the external DB
var amount = 0;
// need to move this part to within C5
// Open a new HTTP Request)
var xhr = new XMLHttpRequest();
xhr.open("GET", "Some_ElasticSearch Server", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var person = JSON.parse(xhr.responseText);
amount = person._source.age; // Grabs the person age // changes the value I ne
$('#chart_328').data('updateto', amount); //updates the above HTML data value
document.getElementById('chart_328_text').innerHTML = amount + '%';
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
///END PART TO MOVE///
// Some other functions to update the block///