Page 3 of 3

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

Posted: Wed May 22, 2013 6:26 pm
by John Herdean

yes it is finally starting to work... I really appreciate you guys taking me by the hand here...

However, there is one last thing thats not working in this area: Theres 2 responses from the server: true or false. I entered some info on the live test app that must trigger a false, but it keeps on popping up the "load_submitted" when it should popup the "load_not_submitted" when the server returns a false. So, I dont know if theres an issue with the java script code i wrote or would it be something else?


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

Posted: Wed May 22, 2013 9:12 pm
by Kateryna Grynko

Hi John,

In Rest Service "submit_load" there is an only response parameter "response". If you want to navigate to another page depending on this parameter then you would need in action "Run JavaScript" for Rest Service replace the existing code with the following:
codeif(data.response=="true") {
$.mobile.changePage("load_submitted.html", {transition: "pop"});
}
else {
$.mobile.changePage("load_not_submitted.html", {transition: "pop"});
}/code


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

Posted: Wed May 22, 2013 10:27 pm
by John Herdean

Hi, i tried that new code and still doesnt work. Same situation - i only get "load_submitted.html" to pop up regardless of a true or false response. Can you please review this again or check inside my app to see if there is anything else i am missing?

I even tried another variation, here are both final codes i tried:

Code #1:

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

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

Code #2:

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

if(data.response=="true") {
$.mobile.changePage("load_submitted.html", {transition: "pop"});
}
if(data.response=="false") {
$.mobile.changePage("load_not_submitted.html", {transition: "pop"});
}


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

Posted: Wed May 22, 2013 11:01 pm
by Harold Gottschalk

On code snippet 1 Have you tried the following if(data.response === true)

BTW var response = localStorage.getItem('submit_load2'); serves no purpose unless you are storing a value at some other point, but even if you are you are not using it in this code snippet.


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

Posted: Wed May 22, 2013 11:27 pm
by John Herdean

Thank you Harold, that does work now...


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

Posted: Wed May 22, 2013 11:33 pm
by John Herdean

the reason is because I am using strings