jQuery处理JSON或数组

Hey guys, I'm having a problem handling my callback data in JQuery. The following is my AJAX:

$(".ajaxPostMessage").submit(function() {

    var action = $(this).attr('action');

    $.post(action, $(this).serialize(), function(data) {
            alert(data);
    });

    return false;

});

My PHP goes something like..

echo json_encode(array('result'=>1, 'msg'=>'message here'));

I can't seem to get the data.result or data.msg to print, I get 'undefined'. I'm wondering if I have to also pass the post as JSON? But that shouldn't matter.. I have also tried $.parseJSON but to no avail!

data will be a string.

You can call $.parseJSON to parse it as JSON.

Try using:

  $.post(action, $(this).serialize(), function(data) {
            alert(data);
    },'json');

This tells jQuery your returned data is json