我正在向 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 请求不起作用。
在 FIreFox 中按 F12,浏览器底部将打开一个窗口。找到控制台选项卡并单击它。然后刷新页面,然后检查 ajax 请求。无论您遇到什么错误,您都会在控制台中看到。您将看到 ajax 调用及其响应。复制粘贴该呼叫和响应,然后指导您。Firebug是Web开发中广泛使用的另一个工具,并且您现在遇到的此类问题。
根据您的评论,不包括 JQuery。请在页面顶部的head部分下包含jquery。JavaScript 脚本中的 $ 符号用于 jQuery,这就是为什么它没有定义 $,因为不包括 jQuery。直接从谷歌包含如下
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
或从 jquery.com 下载
谢谢