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
New Developer
Posts: 14
Registered: ‎11-23-2009
My Device: Not Specified

Widget XMLHttpRequest object

I am developing widget for blackberry using Eclipse which will read RSS/XML  

From external site. I am using XMLHttpRequest object and specifying url of the xml file. here I am putting

button click code..

<input type="button" value="Latest News Local "  class="button" onclick="spXml('abc.xml');"/> &nbsp;&nbsp;

<input type="button" value="nytimesest" class="button" onclick="spXml(URL)"/>

('http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml')

I have added that domain in the config.xml file like

<access subdomains="true" uri='http://nytimes.com'></access>

  

running this widget for local xml file (inside the directory) its working, but external url receiving an error message

Its showing error  TypeError: Cannot convert 'null' to an object.

here I am receiving null in place of text

 

I am using BlackBerry Smartphone Simulator 2.13.0.56

Please can you let me know how to slove this issue?

kamal

Developer
Posts: 168
Registered: ‎11-01-2008
My Device: Galaxy S II
My Carrier: Meteor (Ireland)

Re: Widget XMLHttpRequest object

I notice that the NY Times feed URL you're using returns status code 301 (permanent redirect). Could it be that XHR isn't chasing the redirect? I'm new to AJAX so I don't know what XHR does in the case of redirects. But I know that some HTTP client libraries treat a 301 differently to the other 3xx codes. What happens if you use the 'correct' URL instead? From an efficiency perspective you should be doing this anyway to avoid the unnecessary additional network traffic.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget XMLHttpRequest object

Also, if it is re-directing, make sure that the domain that it is re-directing to is in your <access> whitelist.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 14
Registered: ‎11-23-2009
My Device: Not Specified

Re: Widget XMLHttpRequest object

Dear Sir, 

Thanks for the answer,but still the same issue.. i have change the url like

http://www.timesofoman.com/rss/consolidate.xml

http://www.timesofoman.com/rss/business.xml

http://www.indianexpress.com/rss/798/latest-news.xml

 

but the same issue...can you please let me know...its very urgent...

New Developer
Posts: 14
Registered: ‎11-23-2009
My Device: Not Specified

Re: Widget XMLHttpRequest object

[ Edited ]

 

 

Dear Sir, 

Thanks for the answer, I have modify the JS file,now i am getting another error....

http://www.timesofoman.com/rss/consolidate.xml

http://www.timesofoman.com/rss/business.xml

http://www.indianexpress.com/rss/798/latest-news.xml

 

but the same issue...can you please let me know...its very urgent...

 

here i am attaching my java script code

 

T<script>

function startRequest(getURL){

   var xmlHttp = false;

    xmlHttp = createXMLHttpRequest();

    xmlHttp.onreadystatechange=function(){handleStateChange(xmlHttp);}

     xmlHttp.open("GET", getURL ,true);

    xmlHttp.send(null);

}

 

function createXMLHttpRequest() {

    var xmlHttp = false;

    //try {

    //      netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

    //} catch (e) {

    //      alert("Permission UniversalBrowserRead denied: " + e);

    //}

    if(window.ActiveXObject) {

            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

    }

    else if(window.XMLHttpRequest) {

            xmlHttp = new XMLHttpRequest();

    }else{

            alert("Please upgrade your browser!  Your browser does not support AJAX!");

    }

    return xmlHttp;

}

 

function handleStateChange(xmlHttp){

 

    if(xmlHttp.readyState == 4){

            //if(xmlHttp.status == 200){

                    alert(xmlHttp.status);

                   // alert(xmlHttp.responseText);

                   document.getElementById("to").innerHTML = xmlHttp.responseText;

            //}

    }

}

 

</script>

and this is mine Config.xml file

 

<?xml version="1.0" encoding="UTF-8"?>

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.0">

  <name>Feed6</name>

  <access subdomains="true" uri="http://www.indianexpress.com"/>

  <access subdomains="true" uri="http://timesofoman.com"/>

  <content src="index.htm"/>

</widget>

 

its showing status code 500

 

Could not select proper Transport Descriptor for 

http://www.timesofoman.com/rss/business.xml

 

Could not select proper Transport Descriptor for 

http://www.indianexpress.com/rss/798/latest-news.xml

 

can you please let me know this issue...becuase i am 

new for Blackberry

 

Developer
Posts: 168
Registered: ‎11-01-2008
My Device: Galaxy S II
My Carrier: Meteor (Ireland)

Re: Widget XMLHttpRequest object

It's saying that it could not select a proper transport descriptor. This is probably more something for Tim but it sounds like the widget framework is having a connectivity problem. Are you running this on a physical device or the simulator? If it's a physical device, can you reach those URLs from the browser on the device?

New Developer
Posts: 77
Registered: ‎10-23-2008
My Device: 9000

Re: Widget XMLHttpRequest object

Hi, your question has nothing to do with the BlackBerry development. This is a JavaScript question. Here is an example of JavaScript and XML http://www.codetoad.com/xml_javascripti_tutorial.asp
New Developer
Posts: 14
Registered: ‎11-23-2009
My Device: Not Specified

Re: Widget XMLHttpRequest object

[ Edited ]

 

Dear Sir,

I am using simulator 9500, and how to check framwork connectivty

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget XMLHttpRequest object

Check out the "blackberry.system.hasDataCoverage()" function on the system object:

http://docs.blackberry.com/en/developers/deliverables/11850/blackberry.system.html

 

That should give you what you are looking for.  You can also listen for coverage change on the "blackberry.system.event" object:

http://docs.blackberry.com/en/developers/deliverables/11850/blackberry.system.event.html

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Highlighted
New Developer
Posts: 16
Registered: ‎12-11-2009
My Device: 9500
My Carrier: IT

Re: Widget XMLHttpRequest object

Hi ,

If you are not using webservices how can i Proceed with xmlhttprequest?
I am using Blackberry widget with eclipse can you please give procedure to use the xmlhttprequest.
Till now i am using the following code.

 

 

If you are not using web services , how can you Proceed with xmlhttprequest?

I am using Blackberry widget with eclipse, can anybody  please give procedure to use the xmlhttprequest.
Till now i am using the following code.

 

<script type="text/javascript">

 

        function openRequest()

        {

            try 

            {

                alert("Request Is Openned");

                var req = new XMLHttpRequest();

 

                //req.open("POST", "http://10.80.10.74/service.asmx",false);

                req.open("GET", "http://10.80.10.74/service.asmx",false);

                req.setRequestHeader("SOAPAction", "http://tempuri.org/HelloWorld");

                req.setRequestHeader("Content-Type", "text/xml");

               /* req.onreadystatechange=function()

                {

                    if(this.readyState==XMLHttpRequest.DONE)

                    {

                        alert("Success");

                    }

                }*/

                req.onreadystatechange=function(){handleStateChange(req);}

 

                req.send(null);

                alert('request complete: ' + req.status);

                   if (req.status == 200) 

                    {

alert("200");

                        displayOutput(req.responseBody);

                    } 

                    else if (req.status==404)

                    {

                     alert("404");

                        displayOutput("Error: " + req.statusText);

                    }

 

                    else

                    {

                     alert("unknown");

                     displayOutput(req.responseBody);

                     //displayOutput(req.statusText);

                    }

 

 

            }

            catch(e) 

            {

alert("Catch Block Is Executed");

                alert('exception: ' + e.name + '; ' + e.message);

            }

        }

 

        function handleStateChange(xmlHttp){

          

            if(xmlHttp.readyState == 4){

                    //if(xmlHttp.status == 200){

                            alert(xmlHttp.status);

                           // alert(xmlHttp.responseText);

                           document.getElementById("CallDivId").innerHTML = xmlHttp.responseText;

                    //}

            }

        }

 

        function displayOutput(val) {

            //var sOut = val.replace(/</g,"&lt;").replace(/>/g,"&gt;");

            //sOut = '<b>mPHR Server Status: </b>' + req.status + '<br/><br/><b>mPHR Response Text:</b><br/>' + sOut;

            document.getElementById('CallDivId').innerHTML = val;

        }

    </script>  

</head>

<body onload="openRequest();">

<div id="CallDivId"></div>

</body>

 

But this code does not work properly, It is giving Error Message as 500(ie. Internal Server Error)

How can i add Ajax library in BB app? Is it possible? 

 

 

I am using Vista 32 Bit, and i am using " BlackBerry Smartphone Simulator 2.13.0.56"

In what way i can solve this solution?

I am missing some thing ..Please guide me.