148 posts
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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

815 posts
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 1
  • Freebie
+3 more
rvision_
says

sidebars should be array?

 var sidebars = [];
148 posts
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
Itachicz
says

sidebars should be array?
 var sidebars = [];

still doesn’t work…

110 posts
  • Affiliate Level 1
  • Author Level 5
  • Beta Tester
  • Collector Level 1
+5 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.

2054 posts
  • Affiliate Level 3
  • Author Level 11
  • Collector Level 2
  • Elite Author
+11 more
bitfade
says

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

148 posts
  • 3 Years of Membership
  • Czech Republic
  • Exclusive Author
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