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:
- $find_contact = $_POST['txtFind'];
-
- $mysql_query = $mysql_connection->prepare('CALL sp_find_contact(:param_find)');
- $mysql_query->bindParam(':param_find', $find_contact, PDO::PARAM_STR);
-
- $mysql_query->execute();
-
- $result = $mysql_query->fetchAll(PDO::FETCH_ASSOC);
-
- echo json_encode($result);
and this is the JQuery:
- $.ajax({
- type: 'POST',
- url: "find_contact.php",
- dataType: "json",
- data: $('#frmFind').serialize(),
- success: function(data)
- {
- alert(data["first_name"]);
- console.log(data["first_name"]);
- $("#divResult").html(data);
- },
- error: function(jq,status,message)
- {
- alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message);
- }
- });
Thanks,