0

I need to search for a 'term' and then display the data in the html page. See more info here. http://www.nlm.nih.gov/medlineplus/webservices.html The data that needs to be displayed is

"title"
"FullSummary"
"groupName"
"snippet"

I am a beginner when it comes to ajax and javascrpt

What I have so far is:

<html>
<head runat="server">
<title></title>
<script type="text/javascript">
function DoSearch() {
'http://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term='($get("searchterm"), DoCallback);
}
function DoCallback(result) {
for (var i = 0; i < result.length; i++) {
$get("searchterm").innerHTML += results[i] + "<br/>";
}
}
</script>

</head>


<body>

<form name="input">
      Search Term: <input type="text" name="searchterm" value=""><br>
      <input type="button" onclick="mySearch()" value="Search">
</form>

<div id="searchResultsPlaceholder">resultsDiv
</div>

</body>
</html>

Can anyone advise?

4

1 回答 1

0

Ajax 将基于同源策略工作。假设您在通过 XMLHttpRequest 访问 url 时使用同源策略

<html>
<head runat="server">
<title></title>
<script type="text/javascript">
function mySearch()
{
var term =  $("#searchterm").val();
 $.get("http://wsearch.nlm.nih.gov/ws/query",
 {
 db:"healthTopics",
 term:term
 },
 function(result,status){
 var resultHTML=""
 for (var i = 0; i < result.length; i++) {
 resultHTML + =  results[i] + "<br/>";
}
$get("searchResultsPlaceholder").innerHTML =resultHTML;
  });
}
</script>

</head>


<body>

<form name="input">
      Search Term: <input type="text" name="searchterm" value=""><br>
      <input type="button" onclick="mySearch()" value="Search">
</form>

<div id="searchResultsPlaceholder"></div>

</body>
</html>
于 2014-09-23T04:59:03.277 回答