Software Archive
Read-only legacy content
17060 Discussions

AJAX post calls to web service fail on Build of my App-iOS & Android

Bradley_E_
Beginner
3,015 Views

So i came across this problem last week when i was trying to make a small module for a login screen. 

I used :

app designer
hybrid app
jquery Mobile
login web service using AJAX -- the code snipet for teh AJAX call is at the very bottom

 

So, this worked before the February update of XDK. I used to make small modules and then implement them into my photo documenting app for testing. All modules and previous version of my app work fine with the exisitng code i already had. Now that I have updated XDK a lot of things have gone wrong in my app. I had a previous post a few weeks ago about MY app crashing when i logged in on the emulator and had some serious issues. After figuring everything out with XDK staff i ended up recreating my app with a brand new code base using Jquery mobile and the updated XDK. The javascript has pretty much stayed the same with the exception to using document.location.href (because that used ot make it crash).

Everything works fine in the emulator and using the app preview. But yesterday i tried to build my app for APK and iOS and it wont even login. On iOS it gives me this line :  alert("failed to load login details");}
            So it skips all of my error handling ont he AJAX POST that i gave you below. 

When doing research i found that i needed <Script xhr.js > and <script intelXDK.js> and that they are not included in the index.html page. But the post i have read about these issues do not relate to the newest verion of XDK, but instead older versions. So after trying this quick fix i still cannot send my AJAX post as i used to before. 

The code snippet at the bottom is literally th elogin script i use and it worked on multiple apps i have made in XDK BEFORE the update. All apps that i have that upgraded with the update still can connect using these AJAX type calls, but if i start a new app from scratch and try to use this is fails. I have attached my full app zip to this post as well. I feel like there is jst something im missing or a small glitch. 

Please help me figure this out, ive already completely rebuilt my app to work with the XDK updates because of all the crashing it used to cause and now once again im running into silly problems. 

Any thoughts, comments or answers are much appreciated. If i figure out a solution i will post it as well.

Thanks

//LOGIN SCRIPT
function login(){
    //console.log("login called");
    
    var email = $("#login_username").val();
    var password = $("#login_password").val();
    
    
    $.ajax({
        type: "POST",
        url: "http://54.235.248.192/AppwsVTJN/login.php",
        data:{
            "email":email,
            "password":password
        },
        beforeSend: function () {
        //    $('.loading').show();
        },
        complete: function () {
        //    $('.loading').hide();
        },
        success: function(status) {
                if(status != ""){
                localStorage.setItem("IsLoggedIn",1);
                localStorage.setItem("LoginEmail",email);
                localStorage.setItem("LoginPassword",password);
                
                var new1 = status.split(',');
                localStorage.setItem("companyId",new1[0]);
                localStorage.setItem("userId",new1[1]);
                
                //console.log(localStorage.getItem("userId",new1[1]));
                
               // intel.xdk.notification.alert("Log in Successfull!", "Login", "Close");
              getJobList();
                //document.location.href="#viewjobs_online";
                
                
                ////console.log(localStorage.userId);
                
                //location.href = "#mainpage";
            }
            else{
                //console.log("ERROR");
                 intel.xdk.notification.alert("Log in credentials incorrect!", "Failed", "Close");
               // document.getElementById("userid").value= "";
                document.getElementById("login_password").value= "";
                
                //$("div.error1");
            }
        },
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert("Not connect.\n Verify Network.");
            } else if (jqXHR.status == 404) {
                alert("Requested page not found. [404]");                    
            } else if (jqXHR.status == 500) {
                alert("Internal Server Error [500].");
            } else if (exception === 'parsererror') {
                alert("Requested JSON parse failed.");
            } else if (exception === 'timeout') {
                alert("Time out error.");
            } else if (exception === 'abort') {
                alert("Ajax request aborted.");
            } else {
                //alert("Uncaught Error.\n" + jqXHR.responseText);
            alert("failed to load login details");}
            
            
            $('.loading').hide();
        }
      });
    }

 

0 Kudos
27 Replies
PaulF_IntelCorp
Employee
489 Views

Does your build work properly if you choose the W3C Widget Access option?

0 Kudos
Wesly_L_
Beginner
489 Views

Paul F. (Intel) wrote:

Does your build work properly if you choose the W3C Widget Access option?

 Good day!

also I tried but did not work!

0 Kudos
Emeka_A_
Beginner
489 Views

Good day, Im new to intel xdk but your project is literally what i am looking for. I just wanted to find out if i could see your server side code?. I have learnt alot from your source code, but theres still a lot i don't understand. Please if you can e-mail me: emekatoby@gmail.com

0 Kudos
PaulF_IntelCorp
Employee
489 Views

Emeka -- if you are referring to the XDK server-side code, that is not public code.

0 Kudos
Swati_S_Intel1
Employee
489 Views

@Wesly, Which Android version are you trying on?

0 Kudos
milan_h_
Beginner
489 Views

after intel xdk build app to not working on ajax responding

0 Kudos
Reply