开发者

Ajax in webview not send data to server

开发者 https://www.devze.com 2023-01-14 04:26 出处:网络
The ajax in webview works fine if you keep using it, but if you don\'t do anything and wait for about 10 minutes and try to use ajax to send data to server nothing happens. I checked the server side t

The ajax in webview works fine if you keep using it, but if you don't do anything and wait for about 10 minutes and try to use ajax to send data to server nothing happens. I checked the server side there is no request sent from the ajax in webview. Is it bug of webview or did I mess something up?

The ajax code I use (the jQuery $.ajax with some my own functions):

function extendBaseAjax(paramObj){
if(typeof(paramObj['maxRetryTimes'])=='undefined'){
    paramObj['maxRetryTimes']=0;
}
var maxRetryTimes=paramObj['maxRetryTimes'];
var retryCounter=0;
var error=p开发者_JAVA技巧aramObj['error'];  
var errorHandler=function(XMLHttpRequest, textStatus, errorThrown){
    if(textStatus=='timeout'){
        retryCounter+=1;
        if(retryCounter<maxRetryTimes){
            $.ajax(paramObj);
        }else{
            error(textStatus);//timeout", "error", "notmodified" ,"parsererror"
        }
    }else{
        error(textStatus);
    }
}


var success=paramObj.success;

var successHandler=function(data){
    if(typeof(data)=="string"){
        data=eval('('+data+')');
    }
    success(data);
    }

    paramObj['success']=successHandler;
    paramObj['error']=errorHandler;
    paramObj['date']=new Date().getTime();//no cache
    $.ajax(paramObj);
}

And most of my ajax use like this:

        extendJsonpAjax({
        url:url,
        data:data,
        timeout:timeout,
        maxRetryTimes:maxRetryTimes,
        success:function(data){
            var resultNumber=data['resultNumber'];
            totalPageNumber=resultNumber+1
            totalPageNumber=Math.ceil(resultNumber/limit);
            executeCallBack(data,currentPageNumber,totalPageNumber);
            isAjaxCompleted=true;
        },
        error:function(textStatus){
            errorCallBack(textStatus);
            isAjaxCompleted=true;
        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消