I have a problem like this.
<select onchange="select()" id="select">
<option value="1">test 1</option>
<option value="2">test 2</option>
</select>
I take the value of #select with javascript and send with ajax to php
var clientVal = $('#select').val();
$.ajax({
type:'post',
url:'../../works/addWork.php',
dataType:'JSON',
data:{
client_val:clientVal
},
success:function (res) {
console.log(res);
}
})
php
$client_id = $_POST['client_val'];
$row_subClient = $conn->query("SELECT `id`,`name` from `subClient` where `client_id`=$client_id");
$sub_client_arr = [];
while($result_client = $row_subClient->fetch_assoc()){
$sub_client_arr[$result_client['id']] = $result_client['name'];
}
echo json_encode($sub_client_arr);
There isn't any problem here.After getting in php,I select from database my datas.There isn't problem here too.But when I do json_encode($array),and console.log(res) to javascript.It gives me back all html page with my arrays.Where is my problem,that I get with html? Please help me.Thank you in advance.