admin管理员组文章数量:1279055
Hi there (& Happy New Year!)
Are there some examples on how I can use JQUERY to get XML from a remote REST API and just display the XML? I just need a little assistance to get things going.
Request Details:
https://{username}:{password}@api.opsourcecloud/oec/0.9/myaccount
Response Details:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:Account xmlns:ns2="" .. >
<ns3:userName>rdyer</ns3:userName>
<ns3:fullName>Joe Public</ns3:fullName>
<ns3:firstName>Joe</ns3:firstName>
<ns3:lastName>Public</ns3:lastName>
<ns3:emailAddress>[email protected]</ns3:emailAddress>
<ns3:orgId>1831c1a9-9c03-44df-a5a4-f2a4662d6bde</ns3:orgId>
<ns3:roles>
<ns3:role>
<ns3:name>primary administrator</ns3:name>
</ns3:role>
</ns3:roles>
</ns3:Account>
Hi there (& Happy New Year!)
Are there some examples on how I can use JQUERY to get XML from a remote REST API and just display the XML? I just need a little assistance to get things going.
Request Details:
https://{username}:{password}@api.opsourcecloud/oec/0.9/myaccount
Response Details:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:Account xmlns:ns2="http://oec.api.opsource/schemas/organization" .. >
<ns3:userName>rdyer</ns3:userName>
<ns3:fullName>Joe Public</ns3:fullName>
<ns3:firstName>Joe</ns3:firstName>
<ns3:lastName>Public</ns3:lastName>
<ns3:emailAddress>[email protected]</ns3:emailAddress>
<ns3:orgId>1831c1a9-9c03-44df-a5a4-f2a4662d6bde</ns3:orgId>
<ns3:roles>
<ns3:role>
<ns3:name>primary administrator</ns3:name>
</ns3:role>
</ns3:roles>
</ns3:Account>
Share
Improve this question
asked Jan 1, 2010 at 17:06
SimonSimon
371 gold badge2 silver badges6 bronze badges
2 Answers
Reset to default 7Use the jQuery.get
method.
For example:
$.get(
'https://{username}:{password}@api.opsourcecloud/oec/0.9/myaccount',
function(data) { alert(data); }
);
EDIT: For security reasons, you cannot use AJAX to get data from a different domain. Therefore, you'll need to write a server-side script to get the data from the other domain, then call that using $.get
.
If you just want to display the results of the REST service and you don't care about format or anything, this is what you can do:
<script>
....
$.ajax('<your_rest_service_url>', {
dataType:'xml',
data:{},
type:'GET',
success:function(data, status, response) {
var tmp=response.responseText; // THIS IS THE TRICK
$('#result').text(tmp);
....
</script>
<span id="result"></span>
The trick is NOT use the "data" parameter (like you're suppose to.... and what everyone else on the internet is telling you to do). Just remember, this is quick and dirty.
本文标签: javascriptHow To Use JQuery to Get XML From Remote REST APIStack Overflow
版权声明:本文标题:javascript - How To Use JQuery to Get XML From Remote REST API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741287380a2370348.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论