How do I grab stuff from my website on a local html file

So for my second screen display, I want to grab the customer data and previous purchases from my online database and website. I orginally went through SambaPOS printing out the info in the print template and using scripts to get to the info but this didnt work as there was a noticable lag whilst the info would be downloaded, somtimes causing Samba to go unresponsive. I was at first thinking that I would simply be able to add some AJAX stuff into the print template to retrieve everything from the website once the html has been loaded but I came across the problem of cross domain data calls.

I was wondeirng if anyone here has any experience getting data from a website.

For refence, I will have a url like www.example.com/getorder?id=123456
And at first when the page gets displayed on the second screen it would go loading before turning into the data that url would return

Well, Ive spent a bit of time working on it and have seemed to got everthing working
Here is my printer template:

<!-- saved from url=(0014)about:internet -->
<html>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/cover.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->

<script
  src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
  crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<style>
html {
overflow: auto;
}
h1 {text-align:center;}
h2 {text-align:center;}
</style>
<script type = "text/javascript">
function closeWindows() {
close();
}
</script>
<style>
#close{
position:fixed;
width:100%;
height: 100%;
z-index: 9999;
background-color: Transparent;
background-repeat:no-repeat;
border: none;
cursor:pointer;
overflow: hidden;
outline:none;
}
</style>
</head>
<body>

{ENTITIES}
[ENTITIES]
<script type="text/javascript">
var exload = 0;
</script>
[=TN('{ENTITY DATA:Points}') > 0 ? '
<div id="load">
<h1>Loading...</h1>
</div>
<script type="text/javascript">
exload = 1;
</script>

' : '
<h1> Welcome {ENTITY DATA:CName}</h1>
<h2>Year: {ENTITY DATA:Year} </h2>
</br></br>
<h1>Purchase 6 more drinks for a </h1>
<h1>Free one!</h1>
' ]
<script type="text/javascript">

if (exload) {
$(document).ready(function(){
$.ajaxSetup({cache: false});
   var url = "http://www.example.com/getstamps.php?studentID=" + {ENTITY NAME} ;          
	$('#load').replaceWith($('<div>').load(url));
	
});

}
</script>

</body>
</html>

The trick was injecting some fake headers into the php file to allow browsers to download the file from it.

Out of itnerest, should I not be usin a CDN to get bootstrap/jquery. Does that mean every time I open it it will download?

1 Like

The Browser will probably cache that to avoid downloading every time. If you can look at the Network log in DevTools, you can know for sure.

That said, I generally tend to host library files locally on the webserver, so there is no reliance on 3rd-party sites, and it keeps internet traffic to a minimum because of that. It is just a preference of mine. It is especially useful when the SambaPOS Server is also the Webserver, and if you have no internet connection, you can still host and request pages on your local network. If you were to use a CDN in that case, the GET for the libraries would fail, and in turn, so would the site. Locally hosted does not have this dependency, and it will be much faster than retrieving libraries from the CDN.

2 Likes