Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
tejasagawane
Posts: 27
Registered: ‎07-06-2011
My Device: playbook
My Carrier: blackberry
Accepted Solution

How to call web service?

Hello,

             I want to know that How to call web service from my HTML5 & javascript application.

Please help me to find such detailed like so that i can easily access it. and i want to access online web service (some method of it) i am not concered with how background Web service takes place.

           I only want that when calling some method of web service , i will get the result back.

Please use plain text.
Developer
praveen_rajan
Posts: 163
Registered: ‎05-06-2011
My Device: Playbook
My Carrier: Not Specified

Re: How to call web service?

Please try this out for a WebService call

 

var xmlhttp; 
xmlhttp = new XMLHttpRequest();
xmlhttp.open("get","your url",true);
xmlhttp.setRequestHeader("Accept","application/json");
xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.onreadystatechange=function() {
 if (xmlhttp.readyState==4) {
  if (xmlhttp.status == 200) {
    console.log(xmlhttp.responseText);
  }
 }
} 			
xmlhttp.send();

This displays the result of the webservice call. The url is the request you are making and the type can be get/post. If post xmlhttp.send() takes argument for posting data. This can be called in a button click in HTML.

 

Please use plain text.
Contributor
tejasagawane
Posts: 27
Registered: ‎07-06-2011
My Device: playbook
My Carrier: blackberry

Re: How to call web service?

I am not able to get 

xmlhttp.responseText

 form my web service. my code is going inside code:

 if (xmlhttp.readyState==4)

 but it fails condtion:

 if (xmlhttp.status == 200)

 what is the solution for it?

Please use plain text.
BlackBerry Development Advisor (Retired)
ababut
Posts: 46
Registered: ‎07-08-2010
My Device: Superberry
My Carrier: Rogers

Re: How to call web service?

[ Edited ]

This means that your server has returned a non-200 error code. You should alert it to see what it is and solve the problem.

if(xmlhttp.status == 200) do stuff;
else alert("Server returned: " + xmlhttp.status);

 

PS: Have you modified the "your url" server URL when you copied the above example?

-------------------------------------------------------------------------------------------------
Useful resources, food for the brain:
Web(Works) KB - http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/tkb-p/browser_dev%40tkb
Please use plain text.
Contributor
tejasagawane
Posts: 27
Registered: ‎07-06-2011
My Device: playbook
My Carrier: blackberry

Re: How to call web service?

Yes I have modified url with my server url"

"http://192.168.15.172/Streamer/TestData/sample.txt"  or "http://192.168.15.172/Streamer/StartStream.aspx?IsTestData=true"

 and I am getting " Server returned: 0 " (

xmlhttp.status returning 0 value.

 how to solve this?

)

Please use plain text.
Developer
praveen_rajan
Posts: 163
Registered: ‎05-06-2011
My Device: Playbook
My Carrier: Not Specified

Re: How to call web service?

[ Edited ]

I hope you have whitelisted your server url to config file and sets subdomains true.

 

<access uri="http://192.168.15.172/" subdomains="true"></access>

 

Please use plain text.
Contributor
tejasagawane
Posts: 27
Registered: ‎07-06-2011
My Device: playbook
My Carrier: blackberry

Re: How to call web service?

[ Edited ]

It is also not working on Crome browser getting xmlhttp.status=0, and on  BBplaybook simulator getting xmlhttp.status=406

Please use plain text.