148 posts
  • Czech Republic
  • Has been a member for 2-3 years
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
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
  • Serbia
  • Has been a member for 5-6 years
rvision_ says

sidebars should be array?

 var sidebars = [];
148 posts
  • Czech Republic
  • Has been a member for 2-3 years
Itachicz says

sidebars should be array?
 var sidebars = [];

still doesn’t work…

108 posts
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • United Kingdom
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
  • Has been a member for 1-2 years
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.

1999 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Author had a Free File of the Month
  • Won a Competition
  • Bought between 10 and 49 items
+4 more
bitfade says

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

148 posts
  • Czech Republic
  • Has been a member for 2-3 years
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