【发布时间】:2013-09-24 10:40:51
【问题描述】:
这是我的代码:-
<script>
$(document).ready(function(){ //#This script uses jquery and ajax it is used to set the values in
$("#day").change(function(){ //# the time field whenever a day is selected.
var day=$("#day").val();
var doctor=$("#doctor").val();
$.ajax({
type:"post",
url:"time.php",
data:"day="+day+"&doctor="+doctor,
dataType : 'json',
success:function(data){
var option = '';
$.each(data.d, function(index, value) {
option += '<option>' + value.res + '</option>';
});
$('#timing').html(option);
}
});
});
});
</script>
这是 php 脚本。
<?
$con=mysqli_connect("localhost","clinic","myclinic","myclinic");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$doctor = $_POST['doctor'];
$day = $_POST['day'];
$query="SELECT * FROM schedule WHERE doctor='" .$doctor."'AND day='" .$day. "'";
$result = mysqli_query($con, $query);
$i = 0; //Initialize the variable which passes over the array key values
$row = mysqli_fetch_assoc($result); //Fetches an associative array of the row
$index = array_keys($row); // Fetches an array of keys for the row.
while($row[$index[$i]] != NULL)
{
if($row[$index[$i]] == 1) {
$res = $index[$i];
echo json_encode($res);
}
$i++;
}
?>
我想要在我的 html 页面上的选择中插入时间值的选项,看起来像这样:-
<select id="timing" name="timing"></select>
我的 java 脚本代码可以将值发布到 php 脚本,但该代码仍然无法正常工作。正如我所见,我的 javascript 中没有任何错误。请帮帮我
【问题讨论】:
-
我想你已经把所有的代码都放在了javascript中
-
你能告诉我们你在成功回调中得到的数据结构吗?
-
我知道变量正在进入 php 脚本。当我从主页上的“天”下拉列表中更改值时,它会在控制台中弹出。
-
@SilverBlade 我怎样才能看到数据结构,你能告诉我吗?我是新手:)
-
使用
console.log(data);
标签: javascript php jquery