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
Visitor
Posts: 1
Registered: ‎06-22-2011
My Device: playbook
My Carrier: Not specified

Inconsistant response from XMLHttpRequest on playbook

I am receiving inconsistant response from XMLHttpRequest on playbook.  At times I receive the correct response with status 200. But frequently I receive empty response with status 0 for the same request.

 

 

The javascript is as follows:

 

    var xmlhttp;
    xmlhttp = new XMLHttpRequest();
    xmlhttp.open(this.requestType,this.requestUrl,true);
    xmlhttp.setRequestHeader("Accept","application/json");
    xmlhttp.setRequestHeader("Content-type", "application/json");
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            console.log(xmlhttp.responseText);

            console.log(xmlhttp.status);
        }
    }            
    xmlhttp.send(this.requestParameters);

 

I found the same topic in http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Problem-with-XMLHttpRequest-and-... , but couldn't find a solution.

 

Is there a way to handle this issue?

 

Contributor
Posts: 23
Registered: ‎05-11-2011
My Device: 9800 BOLD
My Carrier: Videotron

Re: Inconsistant response from XMLHttpRequest on playbook

This is "my" working code (but I did'nt try with parameter, JSON or on Apache )...

 

function ajaxRequest()

{

var ajaxrequest = new XMLHttpRequest( );

ajaxrequest.onreadystatechange =

function() {

 

if( ajaxrequest.readyState == 4 && ajaxrequest.status == 200 )

{

handleContent (ajaxrequest.responseText,ajaxrequest.responseXML,ajaxrequest.statusText);

 

}

}

ajaxrequest.open('GET', 'your web service address', true);

ajaxrequest.send( );

 

}

function handleContent(content,contentXML,statusText) {

handleContentXML (content);

}