dopcpc9207 2013-11-12 17:04
浏览 67
已采纳

不调用Ajax请求

I am sending an ajax request on onmouseover function. This is my code

<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>

this is my show_drop_downn() function

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!!
 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.
Parsing JSON Request failed.');
            }else if(e=='timeout'){
            alert('Request Time out.');
            }else {
            alert('Unknow Error.
'+x.responseText);
            }
        }
    }); 
 }

i have already checked through an alert that my show_drop_downn() function is called. But the ajax method is not calling http://localhost/ok/index.php/search/ajax_delete_ntify i have confirmed that with an echo. However when i write the function address in browser it calls the function alright. I dont know what is wrong with my code. Please help me. And if anything is not clear please tell me what more information you need. AGAIN: MY PROBLEM IS THAT AJAX REQUEST IS NOT WORKING.

  • 写回答

1条回答 默认 最新

  • dongpo8702 2013-11-12 17:29
    关注

    In FIreFox press F12 and a window at bottom of the browser will open. Find the console tab and click it. Then refresh the page and then check the ajax request. Whatever error you got, you will see in the console. You will see the ajax call, and also its response. Copy paste that call and response and then will guide you. Firebug is another tool vastly used in web development and for such issues you have now.

    According to your comment JQuery is not included. Please include jquery at top of the page under head section. the $ sign in java script is used in jquery thats why it is giving you erorr of $ is not defined as jquery is not included. Include it as below directly from google

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    

    or download it from jquery.com

    THank you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图