AJAX datatype JSON and HTML
<p>I am following a tutorial about ajax and I have made this script, where I get data as JSON and append them into a table:</p>

<pre><code>$.ajax({
    url: 'insert.php', 
    type: 'POST', 
    data: {data1: name, data2: phone, data3: address},
    dataType: "json", 
    success:function(res){
        //if(data=="success")
        //{
            //alert("Data added");
            //console.log(arr.id);
            $("#trId").before("&lt;tr&gt;&lt;td&gt;"+res.emp_name+"&lt;/td&gt;&lt;td&gt;"+res.ph+"&lt;/td&gt;&lt;td&gt;"+res.add+"&lt;/td&gt;&lt;/tr&gt;");
        //}
    },
    error:function(res){
        alert("data not added");
    }
</code></pre>

<p>And here is the PHP code:</p>

<pre><code>$insert = "INSERT into employee(emp_name, phone, address) VALUES (:emp_name, :ph, :add)";
$insertStmt = $conn-&gt;prepare($insert);
$insertStmt-&gt;bindValue(":emp_name", $emp_name);
$insertStmt-&gt;bindValue(":ph", $pos);
$insertStmt-&gt;bindValue(":add", $address);
$insertStmt-&gt;execute();

//echo "success";
$lastid = $conn-&gt;lastInsertId();
$res = array('name'=&gt;$emp_name, 'ph'=&gt;$pos, 'add'=&gt;$address, 'id'=&gt;$lastid);
echo json_encode($res);
</code></pre>

<p>Our instructor asked us to transform this script, from JSON as datatype into HTML, and make the initial changes for it. But I can't figure out what should the PHP code returns now, and how to append the returned values into the table.</p>

<p>Secondly, why some people use HTML as datatype while JSON is better ?</p>