0

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 Answers 2

1

Try this

var k = data.id; //As pointed out by dfsq thanks to him
$('#' + k).html(data.validation);
Sign up to request clarification or add additional context in comments.

3 Comments

i need to collect the divid its not taking at first place .. assign k first
on firebugging the value of k is not assigning... in script and so I am unable to edit $('#u_name_'+k).html(data.message);
Then it's really need not know what data is coming, can you add the break point there with firebug, and see what's going on.
0

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;
    ...
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.