douqu8828 2016-02-20 16:16
浏览 59

从数据库通过AJAX获取JSON

My code is not working. Can anyone tell me what's wrong with it? I don't get any result from this code. Please help.

<a href="" id="navigation-edit">EDIT MENU</a>   
$(function(){
    $("a#navigation-edit").on(("click"),function(){ 
         $.getJSON("ajax/navigation-edit.php", function(data) {
             $("#result").html(data);
        });              
    });
});

navigation-edit.php

 <?PHP

$result_NavDel = $mysqli->query("SELECT * FROM navigation_dynamic");
while($row = $result_NavDel->fetch_assoc()){
    $data[] = "<li class='animated bounce infinite'><a  href='?".$row['url']."'>".$row['menu']."</a></li>";

}

$implode='<ul class="nav navbar-nav" id="deleteNav">'`.`implode($data).'</ul>';
 echo json_encode($implode);




 ?>
  • 写回答

1条回答 默认 最新

  • dongsuo9982 2016-02-20 16:32
    关注

    You are making a request asking for JSON formatted response when you use $.getJSON().

    However it is clear from intent of your php and callback code you only want text/html returned so just change from using $.getJSON() to using $.get() which will default to text/html


    If you do want JSON then change to something like:

    PHP

    $data=array('text'=>'OK');
    echo json_encode($data);
    

    And change callback of `$.getJSON to:

    $.getJSON("ajax/navigation-edit.php", function(data) {
         $("#result").html(data.text);
    });   
    
    评论

报告相同问题?

悬赏问题

  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏