0

Hi I am unable to retrieve values from json object.The json data as coming like this when observe from firebug :
[{"PROJECT_ID":"CASEENO"},{"PROJECT_ID":"DARKROOM-2"}]

This is my ajax code:

$.ajax({
        type: "POST",
        url: "getdata.php",
        dataType: "json",
        data: { 'dataString': projectid },
        cache:false,
        success:
          function(data){ 
            alert(data);
            for (var i = 0; i < data.length; i++)
            {                               
                $("#projid").append("<option value=data[i].PROJECT_ID>data[i].PROJECT_ID</option>");              
            }           
         }
});

getdata.php code :

$result = mysql_query("SELECT PROJECT_ID FROM projlist WHERE EMPID = 'emp1468'");
    $rowdata = array();
    $rows = array();
    while($r = mysql_fetch_assoc($result)) {
        $rows = $r;
        array_push($rowdata,$rows);
    }   
    echo json_encode($rowdata);
    return $rowdata;
}

alert(data) is giving [object Object].
I tried like this data.PROJECT_ID, data[PROJECT_ID],data[i].PROJECT_ID but project id value is not displaying in select tag.
How can I retrieve from for loop?

1
Contributor
1
Reply
3
Views
4 Years
Discussion Span
Last Post by venkyb47
0

I had find the syntax mistake.Now it is fixed like this

$("#projid").append('<option value='+data[i].PROJECT_ID+'>'+data[i].PROJECT_ID+'</option>');  

Thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.