2017-01-21 1 views
0

누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 메신저가 마약이 무엇인지 찾아내는 fda 검색 웹 사이트를 만들려고합니다. 그것은 fdas API를 사용합니다. 하지만 찾기 버튼을 클릭해도 아무런 변화가 없습니다. json과 ajax 호출을 사용했지만 여전히 작동하지 않습니다. 도움이 많이 접수되었습니다.fda 약 검색 웹 사이트를 만드는 방법

<!DOCTYPE html> 
<html> 



<head> 
    <title>FDA API</title> 
    <link href="https://fonts.googleapis.com/css?family=Julius+Sans+One|Poiret+One" rel="stylesheet"> 
    <link rel="stylesheet" type="text/css" href="css/main.css"> 
    <link rel="stylesheet" type="text/css" href="css/animate.css"> 


    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

</head> 

<body> 

    <nav> 
     <img src="img/fda.gif"> 
    </nav> 

    <div id='wrapper'> 
     <h1 id='title'>FDA DRUG SEARCH</h1> 
      <input id="fdaSearch" type="text" placeholder="Type Name of drug" /><br><br> 
      <button onclick="search()">Search</button> 
     <div id='effects'></div> 
    </div> 
<script > 

function search(){ 
    $("#effects").html(''); 
    var key = "T4No04ciH8D7nIsp6OflpZT1i2JC6XLxd8HUnhIc" 
    var searchTerm = document.getElementById("fdaSearch").value 

    $.ajax({ 

     url: "https://api.fda.gov/drug/event.json?api_key="+ key + "&search=" + searchTerm+"&count=patient.reaction.reactionmeddrapt.exact", 
     dataType: "json", 
     success: function(data) { 
      for(i=0;i<15;i++){ 
       var results = (data.results[i].term) 
      if(data.results[i].term === "DRUG INEFFECTIVE"){ 
      results[i].term = "" 
      }else if(data.results[i].term === ""){ 
      document.write("Try another search") 
      }else{ 
        $("#effects").append(results + " " + "<br>") 
       console.log(data.results[i].term) 
      } 

      } 
     }, 
     type: 'GET' 
    }); 
} 




</script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
</body> 

</html> 

답변

0

jQuery를 사용하여 jQuery 라이브러리를 다운로드하기 전에 스크립트를 실행하고 있습니다. 또한 jQuery의 이전 버전을 사용하고 있습니다.

당신은 jQuery를 지금에있는 <head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 

또는 어떤 버전으로 다운로드 스크립트를 이동해야합니다. src은 jQuery를 얻으려는 실제 소스에 대한 링크 여야합니다. 제가 보여 주는 것은 Google의 것이며 귀하를 위해 효과가 있습니다.

+0

오 도와 주셔서 감사합니다. 이제 작동합니다. –

관련 문제