Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading saveSort widget with jQuery 1.9 throws a JSON parse error #244

Closed
jorisw opened this issue Feb 22, 2013 · 6 comments
Closed

Loading saveSort widget with jQuery 1.9 throws a JSON parse error #244

jorisw opened this issue Feb 22, 2013 · 6 comments

Comments

@jorisw
Copy link

jorisw commented Feb 22, 2013

Hi,

When loading the saveSort widget, I get the following uncaught SyntaxError in Chrome:

Uncaught SyntaxError: Unexpected token u - jquery-1.9.0.min.js:1
st.extend.parseJSON - jquery-1.9.0.min.js:1
$.tablesorter.storage - jquery.tablesorter.widgets.min.js:77
$.tablesorter.addWidget.format - jquery.tablesorter.widgets.min.js:1004
$.tablesorter.addWidget.init - jquery.tablesorter.widgets.min.js:981

Any ideas? TIA

@Mottie
Copy link
Owner

Mottie commented Feb 22, 2013

Hi jorisw!

I think this might be the same as issue #240. I'll have it updated soon.

If it isn't the same problem, please share the error using an un-minified version of the code.

Thanks!


Update: LOL, nevermind, those are the correct line numbers in the unminified version :p

@Mottie
Copy link
Owner

Mottie commented Feb 22, 2013

Ok, this should be fixed now. Please verify it for me!

@jorisw
Copy link
Author

jorisw commented Feb 22, 2013

I get a different error now:

• Uncaught SyntaxError: Unexpected end of input - jquery-1.9.1.js:541
• jQuery.extend.parseJSON - jquery-1.9.1.js:541
• $.tablesorter.storage - jquery.tablesorter.widgets.min.js:77
• $.tablesorter.addWidget.format - jquery.tablesorter.widgets.min.js:1004
• $.tablesorter.addWidget.init - jquery.tablesorter.widgets.min.js:981
• ts.applyWidget - jquery.tablesorter.min.js:1100
• (anonymous function) - jquery.tablesorter.min.js:807
• jQuery.extend.each - jquery-1.9.1.js:648
• jQuery.fn.jQuery.each - jquery-1.9.1.js:270
• ts.construct - jquery.tablesorter.min.js:541
• (anonymous function) - main.js:385
• jQuery.extend.each - jquery-1.9.1.js:648
• jQuery.fn.jQuery.each - jquery-1.9.1.js:270
• initTableSorter - main.js:383
• (anonymous function) - main.js:83
• fire - jquery-1.9.1.js:1037
• self.fireWith - jquery-1.9.1.js:1148
• jQuery.extend.ready - jquery-1.9.1.js:433
• completed - jquery-1.9.1.js:103

Please don't mind the filenames, they are not minified files but they do hold the .min suffix in their filename.

@Mottie
Copy link
Owner

Mottie commented Feb 22, 2013

Sorry, I can't seem to duplicate this problem... I updated this demo page locally to use jQuery 1.9.1 and included the migrate plugin (v.1.1.1) and I get no errors. Everything seems to save, load and sort properly.

Did you try disabling each script on the page until the error disappears?

Actually, try clearing out your local storage, then reload the page.

  • Press F12
  • Go to Resources > Local Storage > Root URL > Find the "tablesorter-savesort" key
  • Right click and choose to delete it.

@jorisw
Copy link
Author

jorisw commented Feb 23, 2013

I've disabled my other scripts except the one that calls the tableSorter plug-in.

When the saveSort widget kicks in, it tries to parse as JSON what is empty, see line 77 of tablesorter.widgets.js. Apparently, in Chrome, this yields the unexpected end error, as it tries to parse ''.

Changing line 77 to this:

v = localStorage[key] ? $.parseJSON(localStorage[key]) : {};

… fixed the problem for me.

@Mottie
Copy link
Owner

Mottie commented Feb 23, 2013

Hi Joris!

Ahh, you're right. I'll change the code to this in the next update (only because it's shorter :P)

v = $.parseJSON(localStorage[key] || '{}');

@Mottie Mottie closed this as completed in 5fef8cf Feb 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants