Software Archive
Read-only legacy content
17061 Discussions

ajax calls

Shawn_A_
Beginner
557 Views

I have an ajax call in my app that works fine in the emulator and on the emulator app, but when I make an APK file, it hangs.

The app collects the user's user id and password, and passes it to the web server.

The web server returns a token and some other user-specific data.

I know the request is hitting the server. The problem seems to lie in parsing the returning json? 

I also know the json is good. How do even begin troubleshooting this?

$("#spinner").show();

                 var uID=$("#userID").val();
                 var uPW=$("#userPW").val();
                 var dataString="userID="+uID+"&userPW="+uPW;
            
            $.getJSON("http://mydomain.com/cgi/mlogin.exe?"+dataString, function(json){

                     if(json.error!=="0"){
                        $("#loginResult").html(json.error);
                         $("#spinner").hide();
                        return;    
                     }

                     $("#loginResult").html("logged in");
                     $("#loginResult").css("color","#ffff00");
                     $("#loginResult").css("background","#000");

                     $("#spinner").hide();
                     $("#loginButton").html("log off");
                     
                     $("#ticketData").html("tickets and stuff");
                     
                     intel.xdk.cache.setCookie("token",json.token,7);             
                     
                     var t="";
                     for(var i=0;i<=json.tickets.length-1;i++){
                        t+="<div class='tRow'>"; 
                            t+="<div class='tNumber'>";
                            t+=json.tickets.ticket;
                            t+="</div>";
                            t+="<div class='tProblem'>";
                            t+=json.tickets.problem;
                            t+="</div>";     
                            t+="<div class='tCustID'>";
                            t+=json.tickets.custID;
                            t+="</div>";      
                            t+="<div class='clr'></div>";
                        t+="</div>";
                     }

                     $("#ticketData").html(t);

                 });

 

 

 

0 Kudos
7 Replies
hakan_k_1
Novice
557 Views

I am not expert but i think don't use  intel.xdk.cache.setCookie or any intel.xdk function.

 

0 Kudos
Hamilton_Tenório_da_
Valued Contributor I
557 Views

Try to show the result using JSON.stringfy(). Maybe you can see something wrong.

0 Kudos
PaulF_IntelCorp
Employee
557 Views

Use the Debug tab, not the Emulate tab to debug this issue. If that does not work, then try using remote CDT with a built app. See this page for lots of debug options: https://software.intel.com/en-us/xdk/docs/intel-xdk-debug-and-test-overview

0 Kudos
Shawn_A_
Beginner
557 Views

Yes it seems the issue was with intel.xdk.cache.setCookie 

What is the better way to set/retrieve a cookie? 

I'm going to try using just plain javaScript.
 

 

 

 

0 Kudos
PaulF_IntelCorp
Employee
557 Views

Use Crosswalk on Android to insure that "just plain JavaScript" works. :) You'll get your best results that way. The Debug tab uses Crosswalk.

0 Kudos
Shawn_A_
Beginner
557 Views

This is how I ended up making it work.

I set a variable to a windows object instead of a cookie

in my login function

setToken(json.token);

then when I need it I just use

var tkn=getToken();

and the functions look like this:

// set token
function setToken(v){
    window.token = v;
    return;
}

// retrieve token
function getToken(){
    return window.token;
}

 

0 Kudos
Shawn_A_
Beginner
557 Views

I'm getting my "testing" phone set up to use the DEBUG tab. 

That's way better than email apk builds to myself.

 

thanks

0 Kudos
Reply