how to get value from ajax response in php?

how to get value from ajax response in php – return value in php after an ajax call by javascript. Look at the response returned from your AJAX request

how to get value from ajax response in php?

JQuery Ajax Call to PHP Script with JSON return using PHP server side code. Steps to make Ajax POST request with JQuery and PHP


 $link = mysqli_connect("localhost", "root", "", "pakainfo_v1");
 $query = "SELECT * FROM member WHERE id = '".$_POST["id"]."'";
 $result = mysqli_query($link, $query);
 while($results = mysqli_fetch_array($result))
  $data["name"] = $results["name"];
  $data["address"] = $results["address"];
  $data["gender"] = $results["gender"];
  $data["info"] = $results["info"];
  $data["age"] = $results["age"];

 echo json_encode($data);

simple return data jquery

        url: 'sendData.php',
        type: 'get',
        dataType: 'JSON',
        success: function(response){
            var len = response.length;
            for(var i=0; i<len; i++){
                var id = response[i].id;
                var membername = response[i].membername;
                var name = response[i].name;
                var email = response[i].email;

                var tr_str = "<tr>" +
                    "<td align='center'>" + (i+1) + "</td>" +
                    "<td align='center'>" + membername + "</td>" +
                    "<td align='center'>" + name + "</td>" +
                    "<td align='center'>" + email + "</td>" +

                $("#memberTable tbody").append(tr_str);


Example : simple return data jquery


include "config.php";

$return_arr = array();

$query = "SELECT * FROM members ORDER BY NAME";

$result = mysqli_query($con,$query);

while($rData = mysqli_fetch_array($result)){
    $id = $rData['id'];
    $membername = $rData['membername'];
    $name = $rData['name'];
    $email = $rData['email'];

    $return_arr[] = array("id" => $id,
                    "membername" => $membername,
                    "name" => $name,
                    "email" => $email);

// Encoding array in JSON format
echo json_encode($return_arr);

How to get values of the AJAX Response?

  var id= $('#member_list').val();
  if(id != '')
     $('#member_details').css("display", "block");
   alert("Please Select member");
   $('#member_details').css("display", "none");

don’t Miss : How To Return Value From Ajax Success Function In Javascript?

Also Read This πŸ‘‰   Ajax Image Upload without Refreshing Page using Jquery

I hope you get an idea about how to get value from ajax response in php.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.