需要使用Javascript/JQuery使用Rest API XML响应
Need to consume Rest API XML response using Javascript/ JQuery
我需要使用JS或JQuery在我的网站上使用Rest API XML响应。有人能提供这方面的代码吗。提前谢谢。
下面是REST API调用,以获得下面显示的XML响应:
/restapi/vc/boards/id/{board id}/订阅/全局/浮动/线程
XML响应
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<response status="success">
<subscriptions>
<subscription type="subscription" href="/subscriptions/global/id/321">
<id type="int">321</id>
<target type="thread" href="/threads/id/4849">
<id type="int">4849</id>
<title type="string" null="true"/>
<messages>
<count type="int">1</count>
<topic type="message" href="/messages/id/4849">
<id type="int">4849</id>
<read_only type="boolean">false</read_only>
<parent type="message" null="true"/>
<teaser type="string"></teaser>
<views>
<count type="int">2</count>
</views>
<subject type="string">Cannot download Pinball Arcade vita</subject>
<deleted type="boolean">false</deleted>
<author type="user" href="/users/id/149">
<login type="string">psforums</login>
</author>
<thread type="thread" href="/threads/id/4849"/>
<board_id type="int">1</board_id>
<message_rating type="float">0.0</message_rating>
<last_edit_author type="user" href="/users/id/149">
<login type="string">psforums</login>
</last_edit_author>
<kudos>
<count type="int">0</count>
</kudos>
<last_edit_time type="date_time">2013-07-24T16:28:44+00:00</last_edit_time>
<post_time type="date_time">2013-07-24T16:28:44+00:00</post_time>
<labels/>
<root type="message" href="/messages/id/4849"/>
<board type="board" href="/boards/id/22034"/>
</topic>
<read>
<count type="int">1</count>
</read>
<linear>
<message type="message" href="/messages/id/4849">
<id type="int">4849</id>
<read_only type="boolean">false</read_only>
<parent type="message" null="true"/>
<teaser type="string"></teaser>
<views>
<count type="int">2</count>
</views>
<subject type="string">Cannot download Pinball Arcade vita</subject>
<deleted type="boolean">false</deleted>
<author type="user" href="/users/id/149">
<login type="string">psforums</login>
</author>
<thread type="thread" href="/threads/id/4849"/>
<board_id type="int">1</board_id>
<message_rating type="float">0.0</message_rating>
<last_edit_author type="user" href="/users/id/149">
<login type="string">psforums</login>
</last_edit_author>
<kudos>
<count type="int">0</count>
</kudos>
<last_edit_time type="date_time">2013-07-24T16:28:44+00:00</last_edit_time>
<post_time type="date_time">2013-07-24T16:28:44+00:00</post_time>
<labels/>
<root type="message" href="/messages/id/4849"/>
<board type="board" href="/boards/id/22034"/>
</message>
</linear>
</messages>
<board type="board" href="/boards/id/22034"/>
<solutions/>
<interaction_style type="string">board</interaction_style>
</target>
<target_type type="subscription_target_type">thread</target_type>
<user type="user" null="true"/>
<subscription_type type="subscription_type">float</subscription_type>
</subscription>
</subscriptions>
</response>
$(function () {
$.ajax({
type: "POST",
url: "URL",
contentType: "text/xml; charset=utf-8",
data: "DATA",
success: function (response) {
$('#result').html('success:');
$(response).find("string").each(function () {
$('#result').append('<br />'+$(this).text());
});
},
error: function (response) {
$('#result').html('failure:<br />' + response.responseText);
}
});
});
希望这将工作
我的反应就像这个
<string>tag 1</string>
<string>tag 2</string>
<string>tag 3</string>
</ArrayOfString>
相关文章:
- 使用angularjs中的rest调用通过id获取数据
- 在同一ip但不同端口上使用Rest API
- 为什么使用AWS Signature v4对S3的REST调用并没有真正使用签名过程
- 如何在使用loopback REST API时更改gulp-angular项目的端口号
- 如何使用REST将AngularJS中的数据POST到Struts2
- 使用javascript中的相同代码为REST服务调用php函数
- 使用Javascript客户端进行REST基本身份验证的安全缺陷是什么(如果有的话)
- 登录后无法使用 ACS REST API 发送推送通知
- 如何使用 Backbone 读取通过同一 REST URL 返回的两个不同对象
- REST API 服务器是否应该使用 PUT 接收 JSON 数据或普通表单数据
- 如何使用已经存在的 REST API 后端在 Angular 应用程序中实现登录系统
- 如何使用angularjs服务将表单参数传递给Rest
- 使用Angular Resource查询具有字符串参数的REST API
- 在javascript中使用rest参数和扩展运算符
- 如何使用Angular.js使用REST
- 使用Ajax使用REST服务-同源策略
- 如何在带有JQuery的Neo4j 2.2.x中使用事务Cypher HTTP端点和新的REST API身份验证和授权
- Angular Factory:实现getAll函数以使用REST-Api
- 在使用Protractor进行测试时,我可以用json文件替换结果,而不是调用实际的REST端点
- 要求使用Django Rest Framework FileUploadParser和Angular File上传的FI