Closed Basirius007 closed 6 years ago
You can use localStorage. But localStorage have limitation of ~5mb(depends on browser). If you want to make big storage to store a lot of data, you should look at IndexedDB or make backend server. But I think the simplest way to store a big amount of data is localforage library.
@olegmisar Don't you need to have installed localforge library on server? And by server I mean where haxball.com/headless is hosted. The problem is cross domain policy. I tried setting cors server locally but couldn't connect to haxball using xmlhttprequest....
How have u tried to connect to haxball? Code, please.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
}
var request = createCORSRequest( "GET", "http://localhost:8123/scoreboard.JSON" );
if ( request ){
// Define a callback function
request.onload = function(){
scoreBoard=JSON.parse(request.responseText);
};
// Send request
request.send();
}
I think it was this one. Error was that I can't acces http server on my pc when it's https protocol.
What browser do u use?
chrome
You have to allow mixed content. Here are solutions for different browsers.
@olegmisar That actually worked :D Problem is now that anyone can access my files at 8123 port xD Still I would need to update my whole scoreboard.json everytime some event happens (player scores goal, team wins etc.). I am not so familiar with php to make backend script on my server to fix that. What do you personally use for storing info olegmisar?
Maybe I will use IndexedDB. Or localforage library, which is a wrapper for IndexedDB. Localforage is simple to use and doesn't require backend, it saves all the data in browser. But you should read about limitations. I believe that IndexedDB doesn't have limits but I am not sure.
@olegmisar Is there way to update indexeddb store without fetching whole player object , updating it and then using put request to update it?
@Wolf72 Do you have discord? I want to ask you something.
@meteus Wolf72x#6765
@Wolf72 Hey, added you. My name is 187#3248
Hello, I have a question if anybody figured out, how to save data, so when i set up new room there are already player names and their goals, assists and so on that the had in previous room?