dongshao1156 2014-02-16 17:35
浏览 43
已采纳

使用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();
}
  • 写回答

2条回答 默认 最新

  • dongna9185 2014-02-16 17:37
    关注

    Try this

    var k = data.id; //As pointed out by dfsq thanks to him
    $('#' + k).html(data.validation);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?