วันอังคารที่ 29 มิถุนายน พ.ศ. 2553

jQuery POST JSON TO PHP Return Endcode From Mysql

//***************** Java Code ***********************
$.ajax({
type: 'POST',
url: 'file_post_and_return_json.php',
dataType: 'json',
data: ({ID:id }),

success: function(data) {
// use data form array //
$('#DIV').val(data[0].FiledName) ;

}
});

/************* PHP Code ************************


PHP get data form Mysql encode to json
query($sql);

$sql = "SELECT *
FROM tableName
WHERE ID =".$_POST[ID]." ;
";
$numrows = $db->num_rows($sql);


$data_rows = array();
$res = $db->query($sql);


while ($row = mysql_fetch_assoc($res)) {
$data_rows[] = $row;
}

echo json_encode($data_rows);

?>

ไม่มีความคิดเห็น: