简体   繁体   English

使用 JavaScript 调用 REST 服务并解析结果

[英]Call REST service with JavaScript and parse results

I want a code for how to parse xml data, which is comming from restfull webservices.我想要一个关于如何解析 xml 数据的代码,该数据来自 restfull webservices。 Please send code for how to call restfull webservices URL from javascript and this URL contains XML data.请发送有关如何从 javascript 调用 restfull webservices URL 的代码,并且此 URL 包含 Z35081BB093D9BCFED315 数据。 I want to read this xml data from javascript.我想从 javascript 中读取这个 xml 数据。

Thank U.感谢你。

You can't grab data from another server using JavaScript, it's a security issue.您无法使用 JavaScript 从另一台服务器获取数据,这是一个安全问题。

You can however create a server-side script which returns the XML required.但是,您可以创建一个服务器端脚本,该脚本返回所需的 XML。 Once you've done that, check out this very helpful article that walks through step by step of using jQuery to parse the XML完成此操作后,请查看这篇非常有用的文章,该文章逐步介绍了使用 jQuery 解析 XML

http://think2loud.com/224-reading-xml-with-jquery/ http://think2loud.com/224-reading-xml-with-jquery/

You can pass/get xml type through Jquery Ajax call.您可以通过 Jquery Ajax 调用传递/获取 xml 类型。 Two important things to be considered while passing the data as xml将数据传递为 xml 时要考虑的两个重要事项

  1. Specifying the datatype as "xml"将数据类型指定为“xml”
  2. Specifying the contentType as "text/xml; charset=\"utf-8\""将 contentType 指定为 "text/xml; charset=\"utf-8\""

You can check out this article for calling your web service through java script and manipulating the data.您可以查看这篇文章,通过 java 脚本调用您的 web 服务并操作数据。

http://sharepoint-snippets.com/ajax-calls-sharepoint-web-services-using-jquery/ http://sharepoint-snippets.com/ajax-calls-sharepoint-web-services-using-jquery/

you can also check for various parameters used in Ajax call http://api.jquery.com/jQuery.ajax/您还可以检查 Ajax 调用中使用的各种参数http://api.jquery.com/jQuery.ajax/

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

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