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

New Contributor
Posts: 4
Registered: ‎10-27-2010
My Device: Not Specified

Optimized Web Service

The pinned post "How "I" would create a Web Service..." was great!  Thanks, it got me started on the right foot.  In it, however, it said, 



Even More Optimized!


You can even take this further by returning <div> statements from your web service instead of JSON.  This is particularly good if you are returning data that is simply for display and does not need to be manipulated in code.  You can then simply dump in the <div> using the innerHTML of an element and not have to do any client side processing.  Since it is returned as a <div> with no formatting, you can then apply a client side CSS to layout the data as you see fit.


Could someone provide a little more detail on this, or possibly an example?  What would the web service need to return, exactly, and how would that change the widget?



New Contributor
Posts: 4
Registered: ‎10-27-2010
My Device: Not Specified

Re: Optimized Web Service

If it is helpful to anyone, here is what I had to do to properly send HTML from the web service to the BB simulator:


        function htmlDecode(input) {
            var e = document.createElement('div');
            e.innerHTML = input;
            return e.childNodes[0].nodeValue;

        function callbackFunction() {
            if (xmlHttp.readyState != 4)

            //<!--Get the Returned Text-->
            var val = xmlHttp.responseText;
            val = val.slice(63);                // Get rid of start characters from transport xml
            val = val.substr(1,val.length-10)   // Get rid of end characters from transport xml
            val2 = htmlDecode(val);             // Decode &lt etc back to regular characters
            //<!--Put the Text into the results DIV-->
            document.getElementById('results').innerHTML = val2;


Posts: 119
Registered: ‎05-27-2010
My Device: 9900
My Carrier: Vodafone NL

Re: Optimized Web Service

[ Edited ]

Please don't foget your HTTP OK's !



if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
//This seems right
} else
//something else



Or you might find yourself in a world of hurt.


Most formulate their request like so:



Function myCall{
xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var xmldoc = xmlhttp.responseXML ; var response = xmlhttp.responseText; // Work with it
} Else
//Something wrong
xmlhttp.open("GET", searchurl, true); xmlhttp.send(); }

 more Examples at:


and for more advanced:



NOTE they now also have HTML5 tutorials:



@reumerd-- @BBDevGroupNL -- about me
If you like it, LIKE it ;-) ----- If it's solved, press solved ! --- If you solved it yourself, please let us know! We might have the same problem!