尝试使用php和mysql实现ajax调用
我已经为我的ajax调用设置了以下内容,但是当我点击一个星型按钮时,它不起作用。这是一个星型评级,尽管如果我直接访问ajax.php,它会插入,但ajax调用不会发生 php文件中的html尝试使用php和mysql实现ajax调用,php,javascript,mysql,html,ajax,Php,Javascript,Mysql,Html,Ajax,我已经为我的ajax调用设置了以下内容,但是当我点击一个星型按钮时,它不起作用。这是一个星型评级,尽管如果我直接访问ajax.php,它会插入,但ajax调用不会发生 php文件中的html echo '<table> <tr> <td style="padding:10px;"> <input type="hidden" name="userID" value="'.$user_id.'">
echo '<table>
<tr>
<td style="padding:10px;">
<input type="hidden" name="userID" value="'.$user_id.'">
<span style="font-size: 20px; vertical-align:top;">Comments</span>
</td>
<td style="padding:10px;">
<textarea name="comments" cols="60" rows="2"></textarea>
</td>
<td>
<div>
<input name="star1000" value "1" type="radio" class="star"/>
<input name="star1000" value="2" type="radio" class="star"/>
<input name="star1000" value="3" type="radio" class="star"/>
<input name="star1000" value="4" type="radio" class="star"/>
<input name="star1000" value="5" type="radio" class="star"/>
</div>
</td>
<tr>
</table>';
JS-用于发送值
<script>
$('.star').rating({
callback: function(value, link) {
var name = $(this).attr('name');
var userID = $(this).closest('td').find('input[name="userID"]').val();
var comments = $(this).closest('td').find('textarea[name="comments"]').val();
$.ajax({
url: "http://localhost/mywebsite/ajax.php",
type: "POST",
data: {
name: name,
value: value,
userID: userID,
comments: comments
},
cache: false,
success: function(response) {
try {
console.log(response);
} catch (err) {
alert(response);
}
}
});
}
});
</script>
我的ajax.php位于
您必须将事件click与函数.rating绑定,以便javascript知道它必须在单击.star时执行函数.rating 你可以这样做:
$(document).ready(function(){
//other javascript code...
$('.star').bind('click',function(){
//your rating function
});
});
在什么事件中,您调用评级函数?当我单击“星”号时,它被调用?否?来上课了你和firebug查过了吗?它是否显示任何错误?请给出绑定/调用此ajaxits的代码。。在html中。。它以班级为主题。明星为活动
$(document).ready(function(){
//other javascript code...
$('.star').bind('click',function(){
//your rating function
});
});