0

This is a follow up to a previous post.

I'm attempting to pass some data to javascript via json_encode.

I thought I would be able to put the data in to a javascript array as follows:

    var data = [<?php echo json_encode($result_array); ?>];

But when I try to call values they return as undefined. I imagine that it might be putting the data as a singular string inside the array.

If anyone can provide advice that would be great. Thanks a lot!

1 Answer 1

2

If $result_array is an array in php, then you just need to do:

var data = <?php echo json_encode($result_array); ?>;
3
  • You are a saint and a scholar. Darwin award for dumbest developer goes to me. (Thanks) Commented Jan 29, 2013 at 2:55
  • Welcome back Daedalus, stack overflow won't let me yet. Commented Jan 29, 2013 at 3:01
  • @spm Purpose of 'welcoming me back', when I've only been here once? Commented Jan 29, 2013 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.