Get json data into a DIV

Get json data into a DIV

Hi,

I am trying to populate data from PHP into a DIV using PHP and JQuery. I am using below code and I am getting the data into the console but I want to ask how can pick a specific field name, e.g first_name or last_name in order to format it in the DIV.

This is the PHP:

  1. $find_contact = $_POST['txtFind'];

  2. $mysql_query = $mysql_connection->prepare('CALL sp_find_contact(:param_find)');
  3. $mysql_query->bindParam(':param_find', $find_contact, PDO::PARAM_STR);

  4. $mysql_query->execute();

  5. $result = $mysql_query->fetchAll(PDO::FETCH_ASSOC);

  6. echo json_encode($result);

and this is the JQuery:


  1. $.ajax({
  2. type: 'POST',
  3. url: "find_contact.php",
  4. dataType: "json",
  5. data: $('#frmFind').serialize(),
  6. success: function(data)
  7. {
  8. alert(data["first_name"]);
  9. console.log(data["first_name"]);
  10. $("#divResult").html(data);
  11. },
  12. error: function(jq,status,message)
  13. {
  14. alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message);
  15. }
  16. });

Thanks,