在安装后首次运行应用程序时从 UIBebView 发出 jQuery Ajax 请求

making a jquery ajax request from a uiwebview on the first run of the application after an install

本文关键字:UIBebView 发出 jQuery 请求 Ajax 应用程序 安装 运行      更新时间:2023-09-26

我们有一个uiWebview,它使用jquery发出ajax请求以便登录。它可以在移动野生动物园和所有浏览器中完美运行。

安装后首次运行应用程序时,ajax 请求似乎已发出,但从未收到任何响应,并且 ajax 请求的失败或完整事件都不会触发。

我们使用了此处的方法:UIWebViewDelegate 不监视 XMLHttpRequest?

监视请求以查看它们是否实际被发送并且它们似乎发出了,但从未收到任何响应。

如果我们然后退出应用程序,终止正在运行的进程并重新启动它,则一切正常。什么会阻止它在第一次运行时工作?

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);          
});

}

我们在网站的后端使用带有Varnish的Drupal。Varnish 正在积极地缓存内容,并且不响应未缓存的请求。 重新启动清漆解决了这个问题。