繁体   English   中英

使用jQuery Ajax Client使用RESTful Web服务

[英]Consuming RESTful Web Service using jQuery Ajax Client

我正在尝试建立一个jQuery客户端来使用MedlinePlus Web服务( http://www.nlm.nih.gov/medlineplus/webservices.html ),但这是我第一次这样做而且无法获得它为我工作:(任何帮助将不胜感激。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Health Topics Web Service</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="javascript">
//http://www.nlm.nih.gov/medlineplus/webservices.html
$(document).ready(function(){
$('select').change(function(){
      $.ajax(
        { url: 'http://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term='+this.value+'&rettype=topic',
        complete: function ( jsXHR, textStatus ) {
        var xmlResponse = $.parseXML(jsXHR.responseText),
            $xml = $(xmlResponse),
            $main = $xml.find('content name="title"'),
            $description = $xml.find('content name="FullSummary"'),
            $('h3#title').html("Title: "+$main.title());
            $('h3#FullSummary').html("Summary: "+$description.FullSummary());
          }
        }
      );

    });
});//ready
</script>
</head>
<body>
<div class="medical">
<h2>Health Topics Web Service</h2>
Select Word : <select name="title" style="width:120px;margin-left:10px;">
  <option value="">Select one</option>
  <option value="Diabetes">Diabetes</option>
  <option value="Migraine">Migraine</option>
</select>
<p id="vBox">
<h3 id="title"></h3>
<h3 id="FullSummary"></h3>
</p>
</div>
</body>
</html>

请提供您遇到的问题。 我想你会得到http://en.wikipedia.org/wiki/Cross-site_scripting问题,因为url是从wsearch.nlm.nih.gov上下文访问的。 如果您确定它是一个休息webservice调用,而不是直接的webservice调用,请执行服务器调用(通过匹配某些URL模式对Servlet / ASP / PHP进行内部调用),然后使用第三个调用Web服务URL 派对RestClient库 例如。 用于JBoss和Java的RestClient

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM