Page 1 of 1

reading service response

Posted: Sat Aug 03, 2013 2:01 am
by John Herdean

Hi, i have a REST service response like this:

{
"result":"pass",
"errorcode":"0",
"body":""
}

and the result will be either 'pass' or 'fail'

and i thought i can write a JS like this:

---------------------------------------------------------------------------------------------

if(result == pass) {
$.mobile.changePage("changes_saved.html", {transition: "pop"});
}
else {
$.mobile.changePage("changes_not_saved.html", {transition: "pop"});
}

-----------------------------------------------------------------------------------------------

but im getting an error in firebug:

ReferenceError: result is not defined

whats wrong with this JS?


reading service response

Posted: Sat Aug 03, 2013 2:05 am
by Alena Prykhodko

Where do you have this JS?
Please tell steps to reproduce.


reading service response

Posted: Sat Aug 03, 2013 2:21 am
by John Herdean

ohh ok, im running this JS on success of Invoking a service inside the DataTab.


reading service response

Posted: Sat Aug 03, 2013 3:23 am
by Alena Prykhodko

You have to define variable 'result'


reading service response

Posted: Sat Aug 03, 2013 1:05 pm
by John Herdean

how do you define a variale in a service response? Like the one i have here:

{
"result":"pass",
"errorcode":"0",
"body":""
}


reading service response

Posted: Sat Aug 03, 2013 9:26 pm
by maxkatz

You should use 'success' callback to get the data from 'data' variable: http://docs.appery.io/documentation/a...