使用json_encode ajax响应作为jquery变量

I am passing the data from ajax process page as

<?php
       header('Content-Type: application/json; charset=utf-8');
       $response = array("username" => "alpha", "message" => 'Passed.', "divid" => 5);
       echo json_encode($response);
?>

In source page I need to collect divid to display the username and message in respective div

success:function(data) 
    {
var obj = $.parseJSON(data);    
    var k = obj[0].divid;
    $('....calling_by_id according to value of k..').html(data.username);
    $('calling_by_id  according to value of k').html(data.message);
    $('.success').fadeIn(200).show();
}

Try this

var k = data.id; //As pointed out by dfsq thanks to him
$('#' + k).html(data.validation);

You don't need to parse JSON yourself, jQuery is smart enough to do it behind a scene:

success: function(data) {
    var k = data.divid;
    ...
}