03-18-2013 06:32 AM - edited 03-18-2013 06:45 AM
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=provi nces&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