.get问题无法获得一行代码

时间:2017-03-03 19:12:09

标签: jquery ajax

我遇到的问题是文档上的最后一段代码。它会不断出现错误。我想要做的是让它从api中提取信息。然后将其添加到#deck1;我一直在收到语法错误。谢谢你的帮助;

$(document).on("click", '#pokelist img', function() {
$.get("http://pokeapi.co/api/v1/pokemon/" +this.id+ "":, function(res) {
$('#deck1').html("<h2>" +res.abilities[0].name +)" "</h2"} 
'json');
})

所有代码

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="style.css"></style>
  <script type="text/javascript" rel="script" type="script" href="script.jss"></script>
  <script type="text/javascript" src='http://code.jquery.com/jquery-1.10.2.min.js'></script> 


     <script type="text/javascript">
        $(document).ready(function() {

          var webaddress = '<img id= "[index]" src="http://pokeapi.co/media/img/[index].png">';
          var pokelist = $('#pokelist');               // get your pokelist

          for (var i = 1; i <= 152; i++) {
            var image = webaddress.replace(/\[index\]/g, i);  // escape your square brackets and make it a global replace
            pokelist.append(image);                           // append it to div
          }

                  });

              $(document).on("click", '#pokelist img', function() {
               $("#deck1").append("<img src='"+this.src+"'>");
              });

              $(document).on

              //below this is the error

               $.get("http://pokeapi.co/api/v1/pokemon/" +this.id+ "":," function(res) { $('#deck1').html("<h2>" +res.abilities[0].name +"</h2>") ; },'json');


  </script>


</head>
<body>


  <div id = "wrapper">






  </div>


  <div id = "pokedeck">

    <div id = "pokelist">


    </div>

      <div id= "deck1"></div>




  </div>




  </div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

$(document).on("click", '#pokelist img', function() {
$.get("http://pokeapi.co/api/v1/pokemon/" +this.id+ ":", function(res) {
$('#deck1').html("<h2>" +res.abilities[0].name + "</h2>")},'json'); 
});