I want to return data from database using AJAX here the AJAX code for retrieving the data but it can't give it saparataly.
$(document).ready(function(){
$('#bathroom-select').change(function(){
var bathroom_option1 =$(this).val();
console.log(bathroom_option1);
$.ajax({
type:'POST',
data:({bathroom_option1}),
success:function(data){
price1=parseInt(data);
console.log(price1);
var rows;
$.each(data, function (key, name) { //this will not work
console.log(item[i]);
});
}
});
});
});
here the database image where the data is stored.
anybody plz explain me i m new on the stackoverflow so if there is any mistake then sorry. And thankyou for replying me the answers.
this is the server site processing using php
$con=mysqli_connect("localhost","root","","price");
if (isset($_POST['bathroom_option1'])) {
$query=mysqli_query($con,"select * from bathroom where number_of_bathrooms ='$_POST[bathroom_option1]'");
while ($row = mysqli_fetch_array($query)) {
echo json_encode($row['price'],JSON_NUMERIC_CHECK);
echo json_encode($row['hours'],JSON_NUMERIC_CHECK);
echo json_encode($row['minutes'],JSON_NUMERIC_CHECK);
}
}