0

We have a uiWebview which uses jquery to make an ajax request in order to log in. It works perfectly from mobile safari and from all browsers.

When running the application for the first time after installation, the ajax request appears to go out but no response is ever received and neither the failure or complete events for the ajax request ever fire.

We used the method found here: UIWebViewDelegate not monitoring XMLHttpRequest?

to monitor the requests to see if they are actually being sent and they appear to go out but no response is ever received.

If we then exit the app, kill the running process, and restart it, everything works perfectly. What could be preventing it from working on the first run?

function makeLoginRequest(){    
//alert('about to make login request');

var loginInfo='{"username":"'+$("#tbUserName").val()+'","password":"'+$("#tbPassword").val()+'"}';      
jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript,application/javascript,text/html,application/json")} });

var loginRequest=$.ajax({
      type:'POST',
      url: 'http://ourURL.com/api/user/login.json',
      data: loginInfo,
      contentType: 'application/json', 
      dataType: 'json',
      success: function(data){
          var sessionID = data["sessid"];
          var session_name= data["session_name"];
          var userID=data.user["uid"];  
          redirectString ='ProfileView.htm?uid='+userID+'&sessionID='+sessionID+'&session_name='+session_name;
          saveUsername();
          $('window').attr('location', redirectString).delay(1000);
          if(enableConsoleLogging)console.log("login attempt succeded.");
          logDeviceData();
          setTimeout(function (){window.location=redirectString;},0);
      }
});     
loginRequest.done(function (data) {
        if(enableConsoleLogging){
            //alert('login attempt complete.');
            console.log("login attempt complete.");
            console.log(data);
        }
});
loginRequest.fail(function(data) {
    if(enableConsoleLogging){
        //alert("login attempt failed.");
        console.log("login attempt failed.");
        console.log("statusText: "+data.statusText);
        console.log("responseText: "+data.responseText);
    }
    loginFailed(data);          
});

}

Community
  • 1
  • 1
gnarbarian
  • 2,622
  • 2
  • 19
  • 25

1 Answers1

0

We're using Drupal with Varnish on the back end of the site. Varnish was aggressively caching things and not responding to requests that weren't cached. restarting varnish fixed the issue.

gnarbarian
  • 2,622
  • 2
  • 19
  • 25