Sorry about the name it should be " issues with XMLHttpRequest" but I had some issues creating this post and tried to make a shorter test post then found I couldn't delete that ……...
I am hoping that there is Sherlock out there that can say I know what this is!
Background
I am creating a management program for iSpy alerts for my own use and have created an example php that uses XMLHttpRequest to read file size and read file content. The php has a recursive function that runs on a timeout that triggers a check of the file size and then a read of the file. The content of the file is written to a text area on the web page.
Sometimes it works and sometimes NOT. I have found that in Firefox, Edge and Chrome my php will often display data that is incorrect, that is, the data is from an earlier read, the file being read can be edited and saved but the output from the php does not match the most recent content in the file. Once this occurs it seems to then not work in any browser Chrome Firefox or Edge until I edit the php save that and restart the weeb page, at which point it MAY come good, muck around for a bit, editing saving and it ultimately it works again until it eventually breaks.
The browser and web server are on the same machine. There is no intent to try and make this work over the wider internet, I understand that reading (writing) files on the Client side could be somewhat .ah. bad
I have attached file_ops_example.php that intermittently triggers this "issue".
Environment
PHP Dev Server and Apache
webspace c:\localweb called edsa-localweb which is hard coded in the file_ops_example.php and would need to be changed for other environments should you wish to try it
a text file alert.txt in the localweb directory ( only needs to contain a single character )
Method
in a browser launch file_ops_eample.php and a text box is displayed on the web page, a javascript function is run in the php that recursively triggers a read of the alert.txt file every second and echos the content to the web page text box
repeat
edit alert.txt and change the content of the file ( it only needs to be one or more characters in my final app its only reading a time stamp nnnnnnnnnnn )
eventually the content being displayed may stop being what you are putting in the text file and it will be something from earlier
change the browser and try the new browser the information displayed by the browser may or may not be correct, but probably incorrect
I found that I can fix the issue in Edge by editing the function checkStatus in file_ops_eample.php and removing the // in front of the line debug... saving the file and tehn refeshing the web page in the browser this puts some extra text on the screen ( a file size) then add the // to the debug line save and refresh the browser and hey presto it's ok again, until it breaks.
Conclusion
I suspect that this is a security issue that is triggered after some time and that the saving of the php with a different filesize somehow resolves some conflict. Or it could be voodoo.
Ultimately I want to use Chrome ( where this problem manifests the most ) Why chrome? Because I am able to display video from a camera in chrome, not in other browsers, and I can cast chrome sticking the web page on a television, "flashing Warning Will Robinson". (the flashing warning is not demonstrated in the sample program )
So, I hope that my explanation has been detailed enough and that someone can offer a "fix", or a reason for what's happening.
alert.txt
anytext (typically nnnnnnnnn for seconds )
file_ops_example.php
I tried posting the whole lot but I got a message saying something to the effect it needs a post.
So I then created a test post, saying "this is a test", that was a bad move, users can't delete posts.
So then I put my original text in the "test post".
Then I couldn't change the title.
Thanks for changing the name for me.
(You can only edit posts for an hour, but we do have a test forum here: http://forums.htmlhelp.com/index.php?showforum=30 )
Afraid I can't help much with the Ajax part, but repeating timer scripts using setTimeout often get stuck if the browser is still waiting for the last one to finish when the next one is started. Don't know any details, alas.
A workaround might be to increment a counter value at the end of checkStatus(), and only restart instance() if both the counter value has increased and a second has passed (can't quite remember if this actually worked, but might be worth a try ).
A perhaps better approach than recursive Ajax calls might be to use https://en.wikipedia.org/wiki/Push_technology but I don't know any details.
ooops So this is acutally a reply to Christians post not to the original post. I will work out how to drive this thing eventually.
Christian,
The editing of the post wasn't a problem I changed it a few times fixing typos but changing the name proved to be difficult maybe users don't have the power. Seemed odd I couldn't delete
Thank you very much for your suggestions to my issue and shall try out your suggestions and report back.
I just spent minutes writing a reply to this post and pressed Preview Post and lost the lot. BUGGER !
So more calmly copied from a text file just in case.
Christian suggested
A workaround might be to increment a counter value at the end of checkStatus(), and only restart instance() if both the counter value has increased and a second has passed (can't quite remember if this actually worked, but might be worth a try
A perhaps better approach than recursive Ajax calls might be to use https://en.wikipedia.org/wiki/Push_technology but I don't know any details.
----
I had a look at https://en.wikipedia.org/wiki/Push_technology but I am afraid I got lost in it and thought it was a bit beyond me.
So I tried his first idea
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)