Question

I am trying to submit an xhr using phonegap on the blackberry. Currently when I make the request it fails silently. I have tried using jQuery jQuery.getJSON(url , callback),

an xhr object

var xmlhttp = new XMLHttpRequest();

//callback function when XMLHttpRequest is ready
xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState==4){
        if(xmlhttpForTGT.status==200){

            response = xmlhttpForTGT.getResponseText()
        }
        else{
            alert("Request Failed")
        }
    } 
}

xmlhttp.open("GET", url , true)
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
xmlhttp.send()

, and xui

x$('#home').xhr(url, 
    {method: 'get',
    callback: function(){ alert('made request') }});

and so far I can't get any of them to work. Has anyone else been able to get xhr's to work? I'm using JRE4.6.1 & using eclipse for the development environment. No errors are thrown when I attempt to make the requests, any advice??

Was it helpful?

Solution

I've contributed a lot to the phonegap-blackberry project, and in all of my tests, for some reason the XmlHttpRequest object always raises an empty exception when you call the open() function on it. I'm not sure why - phonegap-blackberry in its current form leverages RIM's proprietary, non-WebKit browser, so maybe that has something to do with it.

What I've done though is implement a very basic, native, Java-based approach to making HTTP requests and retrieving the response. It is bridged back into JavaScript in your PhoneGap app as part of the 'network' PhoneGap API. Some information about that is here: http://wiki.phonegap.com/Known-issues-(BlackBerry)

NOTE: this is most definitely a stopgap measure. The implementation is rough and could definitely use some work. Currently, it only works with API endpoints that return JSON.

Example usage:

navigator.network.XHR('http://www.mysite.com/myapi',
    'This is my POST data, or I could pass in "null" for empty POST data',
    function(response) {
        // This is my success callback.
        // Do something with the JSON response object here.
    });

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top