PHP AJAX: retrieve data from mysql and show them in form
<p>I am trying to create a autofill form. I have a drop down menu and some form fields like text boxes.
When user click on drop down menu options Ajax call initiate and it will check data in Mysql database. if record found then it will display data in relevant text box.</p>

<p>My code is working fine but i am not able to return data from mysql database.</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(function() {
    $("#autofill").change(function() {
        var data1= $('option:selected', this).text();
                        $.ajax({
                    type: "GET",
                    url:"autofill.php",
                    cache: false,
                    dataType: 'json',
                    data: 'action1=' + data1,
                    beforeSend: function() { 
                        $("#validation-errors").hide().empty(); 
                    },
                    success: function(data) {
                        if(data.success == false)
                            {
                                var arr = data.errors;
                                $.each(arr, function(index, value)
                                {
                                    if (value.length != 0)
                                    {
                                        $("#validation-errors").append('&lt;div class="alert alert-danger"&gt;&lt;strong&gt;'+ value +'&lt;/strong&gt;&lt;div&gt;');
                                    }
                                });
                                $("#validation-errors").show(); 
                                 $('html, body').animate({scrollTop: $("#validation-errors").offset().top}, 2000);
                                btn.button('reset');                            
                            } else {
                                data = JSON.parse( data );
                               $('#title').val('data.title');
                                $('#total').val('data.total');
                                 $('html, body').animate({scrollTop: $("#features-left-image").offset().top}, 2000);
                            }
                    },
                    error: function(xhr, textStatus, thrownError) {
                        alert('Something went to wrong.Please Try again later...');
                        btn.button('reset');
                        alert(thrownError);
                    }
                });             
                return false;
            });

    });
&lt;/script&gt;
</code></pre>

<p><strong>autofill.php</strong></p>

<pre><code>&lt;?php 
require_once('include/db.php');
if(isset($_GET['action1'])){
$search = strip_tags(trim($_GET['action1'])); 
$search = strtolower($search);
$search="%".$search."%";

$result = $mysqli-&gt;prepare("SELECT * FROM posting WHERE title LIKE ?");
$result -&gt;bind_param("s", $search);
$result-&gt;execute();
$result-&gt;store_result(); 
//$result-&gt;bind_result($title);
//$data[]=$result;

echo json_encode($data);
}

?&gt;
</code></pre>

<p>As per my understanding problem is around.</p>

<pre><code>//$result-&gt;bind_result($title);
//$data[]=$result;

echo json_encode($data);
</code></pre>

<p>Please advise me to fix this issue.</p>

<p>Thanks</p>