2

Here is what I'm trying to do:

In "app/design/frontend/default/default/template/catalogsearch/advanced/form.phtml" I have the following php statement

<?php $x=$this->getStoreCategories(); ?>

If I am not wrong $x would be an object and when i display it in php I am able to view it.

I need to convert this object into a javascript object (JSON) as i need to pass it using jQuery Ajax

But when I execute

<script>
var obj = JSON.parse('<?php echo json_encode($x) ?>');
alert(obj.toSource());
</script>

The alert gives me an empty object

Can anyone please help me out

Thanks in advance

Shatir
  • 617
  • 1
  • 5
  • 18

1 Answers1

1

You could do;

<script>
var obj = <?php echo json_encode($x) ?>;
</script>

When the page outputs, your JSON object will be in the page. Or am I missing something about what you want to do?

Anton S
  • 12,750
  • 2
  • 35
  • 37
tbddeveloper
  • 2,407
  • 1
  • 23
  • 39