148 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Czech Republic
  • Sells items exclusively on Envato Market
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
  • 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
  • Sells items exclusively on Envato Market
Itachicz says

sidebars should be array?
 var sidebars = [];

still doesn’t work…

109 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.

2010 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
  • Sells items exclusively on Envato Market
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 :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by