Page 1 of 3

how to trigger a page to nativate to from a json response?

Posted: Tue May 21, 2013 11:25 pm
by John Herdean

Im receiving one of 2 json response. Then, i want to make a certain button go to one of two layouts depending on the json response. I see how to invoke a service in the list of events for the button i want to attach the service to, but how to i tell the service where to go next?

Example: I receive a true response. I want my next action to be a pop-up called success. If i get a false response, i want my next action to go to a pop-up called failure.


how to trigger a page to nativate to from a json response?

Posted: Tue May 21, 2013 11:53 pm
by Igor

Hello,

Save response to localstorage variable "serviceresponse". On invoke service event add Javascript
code
var response = localStorage.getItem('serviceresponse');

if(response) {
// show pop-up success
}
else {
//show pop-up failure
}
/code


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 12:03 am
by John Herdean

ok, but where do i add this javascript?


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 12:42 am
by Igor

select you screen -"Data" tab -select service- event "Success" - action "Run JavaScript"
Image


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 1:36 am
by John Herdean

ok i put it in, but i dont think i did it right, maybe i wrote the code wrong... heres the code i wrote:

var response = localStorage.getItem('submit_load');

if(true) {
show pop-up load_submitted
}
else {
show pop-up load_not_submitted
}

and heres a snapshot of the screen:

Image


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 1:37 am
by John Herdean

how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 1:38 am
by John Herdean

actually, im not sure what to use: 'submit_load' or 'submit_load2'


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 1:39 am
by John Herdean

when i run a live test - i cant even get to the page with the button associated with running that service... that page gets stuck


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 2:16 am
by Igor

This is correct JavaScript code:
code
var response = localStorage.getItem('submit_load2');

if(true) {
$.mobile.changePage("load_submitted.html", {transition: "pop"});
}
else {
$.mobile.changePage("load_not_submitted.html", {transition: "pop"});
}
/code

You should ensure that the service is works and in "localStorage.getItem('submit_load2');" stored correct value.
To verify that the service does not return an error add the following event:
Component "submit_load2" - Event "Error" - "Run JavaScript"

code
alert("Service return Error");
/code


how to trigger a page to nativate to from a json response?

Posted: Wed May 22, 2013 1:15 pm
by John Herdean

ok, so i did it like that and I get the Error message when I run a live test. I did of course test it inside the service test site first to make sure i have a good connection with my server and in fact I had success making a good connection and it does return me a "true" response. So, the only thing that could possibly go wrong is in the java script i wrote. there must be something wrong there. Here are screen shots of what I did so far:

Image

Image

Image