我在onmouseover函数上发送ajax请求。 这是我的代码
<div id="notifications" class="design" onmouseover="show_drop_downn()" onmouseout="hide_drop_downn()">
<button id="notify"></button>
<?php
if($count_notify>0)
{ ?>
<span id="alert" > <?php echo $count_notify; ?> </span>
<div id="drop_downn" onmouseover="show_drop_downn()" onmouseout="hide_drop_downn()">
<?php foreach($values as $row): ?>
<div id="request_display">
<span id="full_name">
<?php
echo $row->fname;
echo " ";
echo $row->lname;
if($row->status=='1')
{
echo " has accepted your friend request";
}
elseif($row->status=='2')
{
echo " has declined your friend request";
}
?>
<br>
<div id="image_short_fake">
<img id ="img_s" src="<?php echo $this->config->item('base_url'); ?><?php echo '/application/css/'. $row->filename?>"/>
</div>
</span>
<!-- <button id="accept" onclick='setSelected_accept(this)' type="submit" value="<?php echo $row->userid; ?>">Accept</button>
<?php ?>
<button id="decline" onclick='setSelected_decline(this)' type="submit" value="<?php echo $row->userid; ?>">Decline</button>
-->
</div>
<?php endforeach; ?>
</div>
这是我的show_drop_downn()函数
function show_drop_downn()
{
document.getElementById("drop_downn").style.visibility = "visible";
$.ajax
({
type: "POST",
url: "http://localhost/ok/index.php/search/ajax_delete_ntify",
success: function(){ alert('ok'); },
error:function(x,e)
{
if(x.status==0){
alert('You are offline!!\n Please Check Your Network.');
}else if(x.status==404){
alert('Requested URL not found.');
}else if(x.status==500){
alert('Internel Server Error.');
}else if(e=='parsererror'){
alert('Error.\nParsing JSON Request failed.');
}else if(e=='timeout'){
alert('Request Time out.');
}else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
}
我已经检查了我的show_drop_downn()
函数被调用的警报。
但是ajax方法没有调用http://localhost/ok/index.php/search/ajax_delete_ntify
我已经确认了回音。但是当我在浏览器中写入函数地址时,它会调用该函数。
我不知道我的代码有什么问题。请帮我。
如果有任何不清楚的地方,请告诉我您需要哪些更多信息。
再次:我的问题是AJAX请求不起作用。
答案 0 :(得分:0)
在FIreFox中按F12键,浏览器底部会出现一个窗口。找到控制台选项卡并单击它。然后刷新页面,然后检查ajax请求。无论你得到什么错误,你都会在控制台中看到。您将看到ajax调用,以及它的响应。复制粘贴调用和响应,然后将指导您。 Firebug是另一种广泛用于Web开发的工具,也是您现在遇到的问题。
根据你的评论,JQuery不包括在内。 请在头部下方的页面顶部添加jquery。在jquery中使用了java脚本中的$ sign这就是为什么它给你的$ eror未被定义为未包含jquery。 直接从谷歌
中包含如下<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
或从jquery.com下载
感谢你