Unable to return/process JSON in JQuery $.get()

Posted by shyam on Stack Overflow See other posts from Stack Overflow or by shyam
Published on 2010-05-07T08:56:32Z Indexed on 2010/05/07 9:08 UTC
Read the original article Hit count: 128

Filed under:
|

I have a problem returning/processing JSON data while calling $.get() function. Here's the code:
JQuery:

$.get("script.php?",
        function(data) {
            if (data.status) {
                alert('ok');
            } else {
                alert(data.error);
            }               
    },'json');

PHP

if ($r) {
    $ret = array("status"=>true);
} else {
    $ret = array("status"=>false,"error"=>$error);
}
echo json_encode( $ret );

So this is the code. But the response is always taken as string in the jquery. data.status and data.error is undefined.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON