好吧,试试这个:
1/ajax调用:
$(document).ready(function(){
$('#bathroom-select').change(function(){
var bathroom_option1 =$(this).val();
console.log(bathroom_option1);
$.ajax({
type:'POST', // you send data with POST method
data:{ "bo1" : bathroom_option1}, //the data you send
dataType : "JSON", // what you will get as anwser data type
url : yourphp.php, // your .php where you send your data
success:function(response){
var data = response.data; // your anwser array with one row = one item with price, hours and minutes
// See why in my PHP, but here you can get the message and the type you send with "response.message" and "response.type", can be usefull if you want to do something different according to what happen in your .php
$.each(data, function (key, name) {
console.log(this); // one row
});
}
});
});
});
2/您的。php:
$result = array();
$con=mysqli_connect("localhost","root","","price");
if (isset($_POST['bo1'])) { // you get your data with post method here, with the key you used in your call, here 'bo1'
$query=mysqli_query($con,"select * from bathroom where number_of_bathrooms ='$_POST['bo1']'");
while ($row = mysqli_fetch_array($query)) {
// You add each row in your $result['data'] array
$result['data'][] = array(
"price" => $row['price'],
"hours" => $row['hours'],
"minutes" => $row['minutes']
);
} // end while
} // end if
$result['message'] = "All is ok !";
$result['type'] = "success";
echo json_encode($result);
// You can send back what you want as message or type for example, if you have some test to do in your php and it fails send back $result['type'] = "warning" for example
这就是你要找的吗?