148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
Itachicz says
hi, I have this code:
        var sidebars = {};
        var counter = 0;

        // Loop through all already crated sidebars
        $('.custom_dynamic_sidebars li').each(function(event) {
            sidebars[counter] = $(this).text();
            counter++;
        });

        var sidebars_string = JSON.stringify(sidebars);
but it gives me this string:
{\"0\":\"aa\",\"1\":\"bb\"}

does anyone know what am I doing wrong?

thx for your time

814 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Contributed a free file of the month
+3 more
rvision_ says

sidebars should be array?

 var sidebars = [];
148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
Itachicz says

sidebars should be array?
 var sidebars = [];

still doesn’t work…

108 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+4 more
designedbydash says

I’m assuming that the string is output via PHP after an AJAX call?

The only thing I think it can be is PHP is adding in slashes due to a configuration on the server (magic_quotes_gpc). If you run stripslashes() on the JSON string before you output it or handle it with PHP and then it should be fine.

The actual PHP config that’s causing it is deprecated, however it’s still used on some servers for security reasons to ensure data is sanitised.

2002 posts
  • Has referred 50+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+9 more
bitfade says

Do you have prototype.js loaded in your page ? because it breaks JSON2

148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
Itachicz says

I’m assuming that the string is output via PHP after an AJAX call?

The only thing I think it can be is PHP is adding in slashes due to a configuration on the server (magic_quotes_gpc). If you run stripslashes() on the JSON string before you output it or handle it with PHP and then it should be fine.

The actual PHP config that’s causing it is deprecated, however it’s still used on some servers for security reasons to ensure data is sanitised.

Thank you so much man it works perfectly :) You have saved me a lot of tyme :) I was working on this issue for a all day but nothing. Thank you very much :)

by
by
by
by
by
by