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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.