Stjames Life
Posts: 0
Joined: Tue Mar 31, 2015 8:06 pm

How to execute REST service and obtain XML response with javascript?

I've seen a number of posts regarding execution of REST service, but haven't found any as of yet (that have worked for me) that dealt with obtaining the XML response of the service. I'm needing to obtain data from the service and then fill a HTML control with pieces of that response.

Basically, I have code like this on my page load:

restservice6.execute({
success: function( e ) {
alert("Success...");
},
error: function( e ) {
alert("Error...");
},
complete: function( e ) {
alert("Complete...");
},
});

I get the Success and Complete alerts, but haven't found how to obtain the response (XML).

Thanks in advance.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How to execute REST service and obtain XML response with javascript?

Hello -

Please check here how to setup the service -- https://devcenter.appery.io/tutorials...

and after that you can call it with JavaScript as you mentioned above.

Stjames Life
Posts: 0
Joined: Tue Mar 31, 2015 8:06 pm

How to execute REST service and obtain XML response with javascript?

Thanks, but setting up the service isn't where I'm having the trouble. Let me tell you exactly what I'm trying to accomplish, maybe there's a better way...

I'm using soundmanager2 api. I've created 2 new javascript (objects), soundmanager2.js and bar-ui.js (the user interface) and a new CSS (object), bar-ui.css.

I've got an HTML control on my starting page. If I put the following code (with hard coded url to audio file) in the control, everything works fine.

Code: Select all

 [url=http://#play]Play / pause[/url] 

  <!-- playlist <ul + <li markup will be injected here -- 
  <!-- if you want default / non-JS content, you can put that here. -- 
   JavaScript is required.

0:00

Code: Select all

  0:00 

 span class="sm2-inline-button sm2-volume-control volume-shade"/span 
 [url=http://#volume]volume[/url] 

<!-- playlist content is mirrored here --

Code: Select all

 ul class="sm2-playlist-bd" 
  li[url=http://www.somewebsite.com/20150322.mp3][b]Bill Johnson[/b] - The Power of the Mind[/url]/li 
 /ul 

But...I need to pull the audio file name from an RSS to get the latest available file. I've tried mapping the service to the control and using javascript to return the updated html and while it renders fine, it does not execute the code within the bar-ui.js.

I found that if I map the RSS to a control on the page, then set a local storage variable to the latest file name using javascript, then create a function to assemble the html (using the local storage variable) and set the HTML control in the page load event...it works, but not the first time. The first time through the local storage variable is not yet set. So...I figured if I could (via javascript) essentially read the RSS response and build the html for the control in the page load event, it should work.

Problem is, I can't figure out how to read the RSS response (XML). I would imagine it would be some code in the success or complete function of the code that executes the REST service, but I haven't seen any examples of capturing that XML response in javascript.

If there's a better way to do this, I'm all ears. If not, I need to know what to put in the success or completion function to capture the XML.

Thanks again.

Stjames Life
Posts: 0
Joined: Tue Mar 31, 2015 8:06 pm

How to execute REST service and obtain XML response with javascript?

oops, didn't think about my html being rendered. Here is the html referenced above:

<!--
<div class="sm2-bar-ui compact full-width flat"
<div class="bd sm2-main-controls"
<div class="sm2-inline-texture"<
<div class="sm2-inline-gradient"<
<div class="sm2-inline-element sm2-button-element"
<div class="sm2-button-bd"
<a href="#play" class="sm2-inline-button play-pause"Play / pause</a
<
<
<div class="sm2-inline-element sm2-inline-status"
<div class="sm2-playlist"
<div class="sm2-playlist-target"
<noscript<pJavaScript is required.</p</noscript
<
<
<div class="sm2-progress"
<div class="sm2-row"
<div class="sm2-inline-time"0:00<
<div class="sm2-progress-bd"
<div class="sm2-progress-track"
<div class="sm2-progress-bar"<
<div class="sm2-progress-ball"<div class="icon-overlay"<<
<
<
<div class="sm2-inline-duration"0:00<
<
<
<
<div class="sm2-inline-element sm2-button-element sm2-volume"
<div class="sm2-button-bd"
<span class="sm2-inline-button sm2-volume-control volume-shade"</span
<a href="#volume" class="sm2-inline-button sm2-volume-control"volume</a
<
<
<
<div class="bd sm2-playlist-drawer sm2-element"
<div class="sm2-inline-texture"
<div class="sm2-box-shadow"<
<
<div class="sm2-playlist-wrapper"
<ul class="sm2-playlist-bd"
<li<a href="http://www.somewebsite.com/20150322.m... Johnson</b - The Power of the Mind</a</li
</ul
<
<
<

--

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to execute REST service and obtain XML response with javascript?

Hi Stjames,

Please specify what event handler you get on this code:

pre

restservice6&#46;execute({
success: function( data ) {
console&#46;log(data);
alert("Success&#46;&#46;&#46;");
},
error: function( e ) {
alert("Error&#46;&#46;&#46;");
},
complete: function( jqXHR ) {
console&#46;log(jqXHR);
alert("Complete&#46;&#46;&#46;");
},
});

/pre

Do you get "Success" and "Complete"? Or only "Complete"?
Also please take a look in the console.

Regards.

Bruce Hoffman
Posts: 0
Joined: Mon Mar 02, 2015 3:26 am

How to execute REST service and obtain XML response with javascript?

I get Success and Complete. I attempt to read the data with:

alert(data);

in the success event and get "data is not defined". I don't think I'm referencing the response correctly.

I did find this and it seems to work: On the Complete event I can get the response from jqXHR.responseText. Unless there's a better way, I'm good with this. I just didn't know the proper way to reference the response object.

Thanks for your help.

Return to “Issues”