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

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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)