0

I have written jquery function as follows.

$(document).ready(function() {
  $(".voteup").click(function() {
    $.getJSON('<?php echo $this->Html->url(array('controller'=>'users', 'action'=>'vote', 'up')); ?>/'+<?php echo $movie['Movie']['id']; ?>, 
        function(data) {
            $.each(data, function(key, value) {
            alert(value);
        });
    });
  });

In view action I am doing like this.

echo json_encode($rating);

The array looks like.

array(
       'MovieRating' => array(
            'id' => '1',
            'thumbs_up' => '10',
            'total_votes' => '20',
        )
    )

How to get that array in jquery?

1
  • Note that in JS it won't be an array, it'll be an object with one property that is itself an object with three properties. Commented Oct 26, 2012 at 11:45

1 Answer 1

2

Use the php function json_encode: http://php.net/manual/de/function.json-encode.php.

Sign up to request clarification or add additional context in comments.

Comments

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.