[英]Ajax call after changing the value of a 'option' tag
I am facing a little problem using ajax. 我在使用Ajax时遇到了一个小问题。
I need when I change the value of 'select' tag's 'option' then it will call ajax and the value which I get from the ajax call will show in 'input' tag named 't_name'. 我需要在更改“选择”标签的“选项”的值时,它将调用ajax,而我从ajax调用中获取的值将显示在名为“ t_name”的“输入”标签中。 But its not working.
但是它不起作用。 What the problem in my code?How can I solve it?
我的代码中有什么问题?如何解决? thank you.
谢谢。
Below is my code : 下面是我的代码:
<select id="teacher_select" class="teacher_select" name="teacher_select" value="Select Teacher">
<option value="">Select Teacher</option>
<?php
while($row=mysql_fetch_assoc($teacher) ):
?>
<option value="<?php echo $row['t_id'];?>"><?php echo $row['t_name'];?></option>
<?php
endwhile;
?>
</select>
<input type="text" name="t_credit" id="t_credit"/>
Ajax : 阿贾克斯:
$('#teacher_select').click(function(){
$.ajax({
type:'post',
url:'get_taken_credit.php',
data: 't_id='+ $('#teacher_select').val(),
success: function(reply_data){
$('#t_credit').html(reply_data);
}
});
});
get_taken_credit.php : get_taken_credit.php:
include('db_connection.php');
$t_id = $_POST['t_id'];
$result = mysql_query("SELECT t_credit FROM teacher WHERE t_id = '$t_id'");
echo $result;
exit();
It seems that the id is wrong, you call #teacher_select
instead of #dept_select
, and try to use 似乎ID错误,请致电
#teacher_select
而不是#dept_select
,然后尝试使用
$('#dept_select').change(function () {
instead of 代替
$('#teacher_select').click(function () {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.