Wednesday, June 10, 2015

Parse JSON in JavaScript



In PHP, I used
        $message['success'] = "Personal Information Updated";
        echo json_encode($message);

to pass $message to Javascript .post
    $.post('stakeholderInfo.php', $(".box#stakeholderInfo div #editInfoForm").serialize(), function(jsonMessage) {       
                            obj = JSON.parse(jsonMessage);
                            alert(obj['success']);
                 
                });


 Here I used JSON.parse to  parse JSON in JavaScript, then display message   alert(obj['success']);

No comments:

Post a Comment