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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
New Member
thghst
Posts: 1
Registered: ‎03-18-2013
My Carrier: Vodacom

Error when getting JSON data from REST services

[ Edited ]

Hi,

I’m trying to GET JSON data from REST service then parse the JSON data.

I have managed to do it on a browser but, I seem to have blatantly failed

to do the same with Cascades.

 

var obj = {};
//var resp = "";
//Create XMLHttpRequest Objects
function createRequest(){
  var result = null;
  result = new XMLHttpRequest();
  return result;
};
        
//Use XMLHttpRequest
var req = createRequest(); // defined above
        
//Create the callback
req.onreadystatechange = function() {
  if (req.readyState != 4) return; // Not there yet
    if (req.status != 200) {
      // Handle request failure here...
        return;
    }
  };
        
  var GetData = function(url){
  //Send the Request
  req.open("GET", url, true);
  req.send();
        	
  //Request successful, read the response
  resp = req.responseText;  // Non-parsed JSON response
        	
  //... and use it as needed (Parse it)
  //obj = JSON && JSON.parse(resp) || $.parseJSON(resp);
  //obj = eval(resp);
  obj = JSON.parse(resp);
        	
  return obj;
  //return resp;
};

var data = GetData("http://app.compleatgolfer.co.za/service?view=provinces&token=gxRT67ALqp");

This works on IE browser but not on Cascades.

 When i try 

console.log(rep.status)

 or 

console.log(rep.responseText)

 I get "undefined"

 

Any help would be apreaciated.

 

Note: The code above, in my project, start on the 3rd line of the code below:

Page {
    onCreationCompleted: {

    }
}

 

 

Thanks

Please use plain text.