Jump to content


Photo

Buttons Call-Up Wrong Text File But Only After F5 Refresh


  • You cannot start a new topic
  • Please log in to reply
342 replies to this topic

#1 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 06 September 2016 - 08:22 PM

There are five buttons, each calling up text from five associated .txt files.

When a browser is first opened, the buttons call up the correct associated text files.

But do an F5 refresh, and the buttons call up the wrong text file, most but not all of the time.

Same thing in Firefox, IE, and Chrome.

 

If you like you can try it out:

1) Open a browser > go to kwunk.com/prototype

2) Click some buttons: you'll see that all button clicks call up sentences from the correct .txt file
3) Do an F5 refresh and most button clicks will call up sentences from the wrong .txt file
4) Close/reopen the browser and it'll be back to correct sentences.

 

Is this a cache issue? It happens in Firefox, IE, and Chrome.

All suggestions welcome :P



#2 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 07 September 2016 - 08:47 AM

That's weird!  It also hapens in Edge, FWIW, suggesting it's a site issue.

 

Are you able to post your code?  It's like it's being randomised!

 

Update: Now tried it on Chrome, and couldn't repeat it.  Neither could I repeat it on Firefox either.

It seems like you may have an uninitialized variable somewhere, that's the usual cause for this kind of error.


If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#3 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 07 September 2016 - 10:42 AM

Update:

Just ran up my Ubuntu system and tried it again, using Firefox 48.0 as the browser.

The problem manifested itself straight away, without having to press F5 Refresh.

I got the wrong order when I pressed the top row of buttons, so I saved the page

I then pressed F5, and verified that the order was different - it was

So I then saved that page, and then ran 'diff' against them to get the differences.

None.

So it's a server-side thing - when your page goes back to the server to get the content, check that you don't have an uninitialised variable, or something like that.


If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#4 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 07 September 2016 - 11:39 AM

That's just awesome, Angoid, thanks so much.

If you still need it, I'll send you all the code, but I don't know what's the best way to do that, what do you recommend?



#5 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 07 September 2016 - 12:54 PM

Hi again, Angoid ~

Here's the comment of a friend who's been giving me some advice:

 

Amgoid's answer is where you'd have to start debugging your code...looking for a variable that isn't persisting between postbacks, or is getting reinitialized each time the page loads.

He's saying that the HTML generated by the server is identical, so something is going on before the HTML is generated (server side) and is sent to the browser.

But now that I think about it, this is a little strange, because I didn't think there was anything being done server-side. All the JS is being sent the user's computer, where it runs locally each time. Maybe that's the problem...any variables you are setting that control the buttons are being wiped out each time the page is reloaded.

The problem might be you are not "persisting" a variable between postbacks to the server. Without diving into your code I couldn't tell you more than that, but it's something for the programmer to look at.

You might need to be storing something between page reloads that is being reset each time...either saving the value in a cookie, or in a session variable, or somewhere where to JS can reload it each time the page runs. Even in a querystring.

If you look at the first answer on this page, it might help:

http://stackoverflow...-on-page-reload



#6 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 07 September 2016 - 01:26 PM

Just looking at the comments on SO, and it's possible it could be JavaScript - that would explain why a DIFF showed nothing, as I was expecting something to be done server-side so didn't investigate any further.

 

However, when I visit the page in your link now, I get the following message:

"Error.  I was expecting a sentence file but could not find one."

I have to click that five times, and on each click the screen fades in, and when finished there are no buttons along the top.

 

I take it you're working on it right now?


If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#7 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 07 September 2016 - 01:32 PM

Try debugging this code to see if it's being set up the way you want:

for (var f in sentenceFiles) {

 

            jQuery.get('sentences/'+sentenceFiles[f]+'.txt', function(data) {

                       i = counter();

                        var sentences = loadSentences(sentenceFiles[i], data);

                        sentenceLists[categories[i][0]] = {

                            'sentences': sentences,

                            'counter': 0,

                        }

                        addButton(files[i]);

 

            }, 'text').fail(function() {

            alert( "Error. I was expecting a sentence file but could not find one." );

          });

You could just put some text out to the screen to see what's in your variables - it looks ugly, but at least it will show you what's going on - you just remove it afterwards.

 

That's a starting point.  If it's going wrong in there, then you've found your error.  Otherwise, look further along the code.  I suspect it could be something to do with that counter(); handled in the loadFiles() method defined just above this code.


If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#8 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 07 September 2016 - 04:09 PM

Yep, I'm working on the page now so everything's bolluxed up.

 

Alas, I'm way too much of an amateur to know how to deal with your suggestion of  <<Try debugging this code to see if it's being set up the way you want:>>

Sorry!



#9 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 08 September 2016 - 11:44 AM

OK, the whole site has gone now  :blink:


If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#10 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 09 September 2016 - 01:17 PM

I've just talked with HostMySite, the tech guy spent a good deal of time trying it out and studying the code (index.htm and app.js)

 

He thinks it's a js issue, and indeed he referred me to the same code you did, Angus, starting with

for (var f in sentenceFiles) {

but he's also willing to continue working on the issue, so I can call him back any time.

 

In further trials, I see it's common that once the wrong call-ups start, it often happens between just two sentence groupe, e.g. Kids calls up People and vice-verse, but the other three call up only themselves ,, like I say, this is common but certainly not always. (Gnashing of teeth sound).

 

The current version is now at http://kwunk.com/from-london-9-8-16/



#11 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 09 September 2016 - 01:26 PM

Hi again Angus ~

 

Chris at HostMySite did indeed eagerly attack the problem, spent quite some time on it, and even suggested that you, me and him have a conference call about it, which I think is far too much for me to ask of you!!!, so I told him you're in a distant time-zone . . but the main thing is I can call him back any time you come up with possibilities, whether or not they're server-side related.

 

Was http://stackoverflow...-on-page-reload  any help?



#12 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 10 September 2016 - 02:33 PM

Hi Beau,

I think that's a case of the spirit is willing but the flesh is weak ... that is, the time-zone thing as well as my R/L and work commitments could get in the way.

I may be able to test your code if I had suitable access to your server, but I sent an email where I suggest that the error might be in the following line in app.js:
var sentences = loadSentences(sentenceFiles[i], data);
I think it should be:
var sentences = loadSentences(sentenceFiles[f], data);
Because every other reference to the sentenceFiles[] array is using f as its index, not i ... could that be your issue?

It's line 41 and posted in the code I pasted above (I think I said 40 in my email to you, miscalculated because I'd added some debug lines and ran it locally but this failed because of the server-side aspects of jquery).

Edit: Further playing with the code over the weekend resulted in not being able to get the jquery.get() method to access files on the server, even though I modified the code to point to the full path.
Because of that, I wasn't able to debug it the way I would have liked, but give the above a whirl first and let us know the outcome.

We can always take another look if need be and discuss how we can go about this.

If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#13 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 12 September 2016 - 01:23 PM

Hi Angus, hope you had a good weekend ~

 

You said in your comment above:

the error might be in the following line (line 39) in app.js:
var sentences = loadSentences(sentenceFiles[i], data);

I think it should be:
var sentences = loadSentences(sentenceFiles[f], data);

 

Don't you mean it the other way around? Line 39 already is  sentenceFiles[f] so aren't you suggesting changing it to (sentenceFiles[i] ?

(Just to be sure, I checked versions of app.js all the way back to February, and line 39 has always been  sentenceFiles[f])

 

So I've tried it out, changed line 39 to (sentenceFiles[i] and running locally the message comes up: "Error: I was expecting a sentence file but could not find one"

expecting%20sentence%20file.jpg

So it looks like that's not the solution.

 

I noticed that app.js also has a "category" element, e.g. line 27 and others; doesn't this refer to Kids/People/Classic/Culture/Genius grouping?

There are sectionis that seems to refer to sentences within category:

line 263: function getSentence(category) {
        var sentenceIndex = sentenceLists[category]["counter"];
        var sentences = sentenceLists[category]["sentences"];

and line 80: for (i in categories) {
          if (categories[i][0] == filename) {
          categoryName = categories[i][1];

 

It seems to me that the problem is the wrong categories are being called up, not the wrong sentences, so I'm wondering if those category lines contain the bug. Just a guess on my part, let me know if it makes any sense :o)



#14 Angoid

Angoid

    Administeriosis Extremus

  • Administrators
  • 1,506 posts
  • LocationEast Midlands, UK

Posted 12 September 2016 - 02:00 PM

I was getting the same error, "Error: I was expecting a sentence file but could not find one" regardless but then my copy of your code is running locally, not from the Web server. That can make a difference.

You could try adding a line in like this:
[code=auto:0]document.writeln("Using i: " + i + " - " + sentenceFiles[i] + "; using f: " + f + sentenceFiles[f] + "<br>");[code=auto:0]

or perhaps this:
[code=auto:0]alert("Using i: " + i + " - " + sentenceFiles[i] + "; using f: " + f + sentenceFiles[f]);[code=auto:0]

after the line that sets i to counter(); and seeing what that shows up. The first on may mess your layout up, and the second one will pop up a dialogus box every iteration of the loop. Either way, it'll show you what's in the variables.

I'm at work right now so don't have access to the code except via View Source .. I'll take another look and let you know what I find.

If you don't know what eschatology is then don't worry; it's not the end of the world.
Please do not send uninvited PMs requesting support; post into the appropriate forum instead and we'll all learn. See our Private messaging policy.


#15 beau

beau

    Valued Member

  • Gold Star Member
  • Pip
  • 555 posts

Posted 12 September 2016 - 02:20 PM

<<my copy of your code is running locally, not from the Web server. That can make a difference.>>

I just ran it online with the jQuery.get('sentences/'+sentenceFiles[f] line, got the same error message about expecting a sentence file.

 

<<at work right now so don't have access to the code except via View Source>>

OK, I guess you have all the code in my email of three days ago

 

I'll try out those lines you've just suggested, be back to you in a coupla hours.