【问题标题】:Jquery Ajax UnderfinedJquery Ajax 未定义
【发布时间】:2017-04-21 06:15:19
【问题描述】:

你好,我是这里的新手,
我想问几个关于jquery的问题
1. 如何在 PHP 中隐藏 undefined
2. 如何在API中命名inside name

这是我的编码 Index.php 或

mediamonitoring.comyr.com/jquery.php

或者这个

 <!DOCTYPE html>
    <html>
    <head>
        <title>Tutorial</title>
        <link rel='stylesheet' href='css/css.html'/>
    </head>
    <body>
    <h1>jQuery Ajax Tutorial</h1>
    <h2>Name Age</h2>
    <ul id="tutor">

    </ul>


    </body>
    </html>
    <script src='js/jquery.js'></script>
        <script src="js/index.js"></script>
        <script src="js/main.js"></script>


    </body>
    </html>

还有我的 Main.js

$(function(){

  var $tutor = $('#tutor');
  $.ajax({
    type: 'GET',
    url: 'http://rest.learncode.academy/api/johnbob/friends',
    success: function(tutor) {
      $.each(tutor,function(i,ex){//the new item is returned with an ID
        $tutor.append('<li>Name:'+ex.name+', Age '+ex.age+'</li>');
      });
    }
  });
});

【问题讨论】:

  • “如何在 API 中命名内部名称”是什么意思?
  • 如果你看到这个 API rest.learncode.academy/api/johnbob/friends ["","","","","","","",{"name":"Billy Bob","age ":"28","id":"58dc0ffd03c59701005b04d5"},[{"name":"Best","age":"29"},{"name":"Michael","age":"34" },{"name":"Genevieve","age":"26"}],如果你看到我的页面,你会说欠精细。我知道它被低估了,因为那里没有价值“”。 name inside name 我所说的是如何显示最佳名称

标签: jquery json ajax api


【解决方案1】:

没有 1. 使用 if, if(variable == null){ //hide }

没有 2. 用这个改变你的 main.js

$(function(){
  var $tutor = $('#tutor');
  $.ajax({
    type: 'GET',
    url: 'http://rest.learncode.academy/api/johnbob/friends',
    success: function(tutor) {
      $.each(tutor,function(i,ex){//the new item is returned with an ID
        if(ex.name != null && ex.age != null){
            console.log(ex);
            $tutor.append('<li>Name:'+ex.name+', Age '+ex.age+'</li>');
        }        
      });
    }
  });
});

【讨论】:

  • 感谢您的回复。其实我不知道如何解释它,但我希望你的解释是我的答案。好的,我会告诉你我真正想要什么 [链接]mediamonitoring.comyr.com/jquery.php 这是我的网站,我想删除那个未定义的。任何我的第二个实际上如果你看里面的 api 得到名字里面的名字。所以我想显示它,我已经使用 +ex.name[name]+ 但我没有为我工作@denny-sutedja
  • 查看我编辑的答案。如果那仍然不是您要寻找的答案,请编写您想要的示例结果。
  • 它有效.. 谢谢。如果我想显示我的第二个数组怎么办?
  • 创建新问题。
  • 这是我的第二个问题。如果你在这里看到 api rest.learncode.academy/api/johnbob/friends 它只显示 Bob 不显示 Best , Michael , Genevieve
【解决方案2】:

这是我的答案,伙计。时长

 <html>
      <head>
        <title>JSON/Atom Custom Search API Example</title>
      </head>
      <body>
        <div id="content">
            <input type="text" id="name">
            <button id="add">Add</button>
        </div>

        <script>
         function hndlr(response) {
        for (var i = 0; i < response.items.length; i++) {
            var item = response.items[i];

            // in production code, item.htmlTitle should have the HTML entities escaped.
            document.getElementById("name").innerHTML +="<br>"+"<b>"+ item.title + "</b>"+"<br>" +item.snippet  + "<br>"+"<a href='"+item.link+"'>"+item.displayLink+"</a>" ;

        }
    }
        </script>
        <script src="https://www.googleapis.com/customsearch/v1?q=response&cx=004123968310343535430%3Aaxml6iel9yo&key=AIzaSyDxPcphnrcN9_dfkRkFTbwkv44m1-HI1Hg&callback=hndlr">
        </script>
      </body>
    </html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-24
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    相关资源
    最近更新 更多