simpleHTTPServer, saveStrings / ajax?

Hello everyone, I am using the SimpleHTTPServer by transfluxus. It works great, but I am have some general HTTP questions.

I want to host a local site that has constantly updating information.

This is my current workflow:

//index.txt file has the base formatting for the page as well as "?REPLACE?" keywords
//Find and replace the specified keywords.
SaveStrings(index.html, data)

Because the information is constantly changing, I set the page to reload after x seconds. This causes the browser to every so often lose the file. In the browser, index.html is completely blank.

I am assuming this is because I am saving a new file every draw cycle and if it ever gets out of sync the browser will lose all data as well as the function to refresh.

So, is there a way I can write a function to only modify the file after a certain point? Or, leave index.html alone and instead write to a completely different html file that gets served instead? This way the function to refresh would always be there?

Separately, is there a way of triggering a client’s browser to refresh only when the server has new information?


Solving my own question, I was able to do everything with AJAX requests. Took me a while to understand, and I still don’t understand fully, but this seems to be the best route for this problem.

More information on AJAX in the SimpleHTTPServer Library, here.

1 Like