arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

SyntaxError on page change - bounty of €100 #132

Closed cliffstudio closed 6 years ago

cliffstudio commented 7 years ago

After clicking on a page link I keep repeatedly getting the following error: SyntaxError: Unexpected identifier 'img'. Expected a ';' after the for loop condition expression.

This is preventing a change in the URL, it's highlighting this error in the title tag of the site, anyway not sure what's causing it, can provide a link if needs be? If anyone could shed any light that'd be great!

arvgta commented 7 years ago

EDIT: Solved in the course of this discussion at jQuery forum - The bounty of €100 went to "jakecigar"


Is this happening within an inline script? If yes, my guess is:

Because it's occuring in a for loop, that you have a "less than sign" ("<") followed directly by an alpha-character. Please try adding a space between the "<" character and the letter. This is a known error in jQuery core, which I currently don't know how to fix. (I have worked around the same bug on 4nf.org, as described above)

For example, it might be worth trying to:

and then

cliffstudio commented 7 years ago

Ah I see, thanks for getting back to me on this one...You can see the bug in question here: http://elliottdev.nealfletcher.co.uk

If you click on 'Studio' in the top right, you'll see the error in the console. Where would you suggest adding the space exactly?

arvgta commented 7 years ago

Thanks for your swift reply and the link! Because I'm currently not at my own PC, I can't see the exact text of the error message. Please try adding the space directly after the "less than sign"...

Here - I think I've pinpointed it:

h<i.length;h++

Just add a space after the "less than sign"

cliffstudio commented 7 years ago

I think I've got to the bottom of it – there was some inline script being added by Wordpress that contained a < sign, disabling this has fixed that issue :)

One small problem now though is that the URL doesn't seem to be updating on page change for some reason?

arvgta commented 7 years ago

Glad we found the exact position of the error.

I just checked the console - very weird - no other errors...

Just another guess -> maybe Wordpress needs the inline script you disabled. Maybe the ideal solution is to really insert a space in the inline script instead. (You may be able to edit the PHP of the respective plugin in the WP-Admin)

cliffstudio commented 7 years ago

Hmm I don't think so as the URL wasn't changing before this script was disabled. The script in question is the emojicon script that's added by default by WP to enable emojicons. Any other ideas?

arvgta commented 7 years ago

Am thinking, but no other ideas at the moment... Might have a look at your HTML when I have the time...

arvgta commented 7 years ago

One thing that came to my attention is that the canonical URL always seems to be:

<link rel="canonical" href="http://elliottdev.nealfletcher.co.uk">

...for both "Work" and "Studio"?

Ajaxify uses the canonical URL, when it is given...

EDIT: Forget about this last comment - it was because the page wasn't re-loading

arvgta commented 7 years ago

Regarding a solution to the original problem - the "less than sign" that causes the inline script to crash - it would require, in a first step, to catch the error when appending the failing inline script.

I have tried various

try...catch

statements in different places, but they don't seem to prevent a "hard error" - in effect, they do nothing at all.

I believe, that would be the first step to combat the bug...

Here is the salient code explicitly:

 addtext: function (t, type) { //Add one inline JS script - main function
        if(!t || !t.length) return; //Ensure input
        if(!type) type = 'text/javascript'; //Validate type
        if(inlineappend || !type.iO('text/javascript')) try { return _apptext(t, type); } catch (e) { $.log("Error in apptext: " + t + "\nType: " + type + "\nCode: " + console.debug(e)); }

        try { $.globalEval(t); } catch (e1) { //instead of appending, try an eval
            try { eval(t); } catch (e2) {
                $.log("Error in inline script : " + t + "\nError code : " + e2);
            }
        }
    },
    apptext: function (t, type) { //Append a single inline script to the main content div
        var scriptNode = document.createElement('script'); //low-level assembly of script node
        scriptNode.type = type;
        scriptNode.appendChild(document.createTextNode(t));
        try { cd0.appendChild(scriptNode); } catch (e)  { $.log("Bad inline script text in apptext: " + t); }
    },

Any ideas?

arvgta commented 6 years ago

Fixed presumably! Therefore closing...

arvgta commented 6 years ago

Summary: When encountering this bug, please edit the PHP of the plugin causing the error and insert a space after the "less than" sign or disable the respective plugin altogether.