dongxianshuai8927 2014-02-11 15:10
浏览 49
已采纳

超时 - 在PHP脚本期间的加载程序

I have a php script that is insert large result on my mysql dbb. I did jquery script to waiting the end of the php script. But I have a timeout error. Do you have an idea to change the timeout to let the script do his job ?

Thank you

Jquery script :

  <script type="text/javascript">
    var dataReturn='';

    function makeRequest(url){
        $('#preloader').show();
        $.get(url, function(data) {
            timeout: timeoutvalue
            $('#resultDiv').html(data);
            $('#preloader').hide();
        }).fail(function() {
            alert( 'Error occured during requesting the page' );
            $('#preloader').hide();
        });
    }

    function makePostRequest(url, params){
        $('#preloader').show();
        $.post(url,params, function(data){
            $('#resultDiv').html(data);
            $('#preloader').hide();
        }).fail(function() {
            alert( 'Error occured during requesting the page' );
            $('#preloader').hide();
        });
    }

    </script>
    <style>
        #preloader{
            display:none;
        }
    </style>

Button to start de script :

<input type="submit" onClick="makeRequest(\'inserttodbb.php?fonction=import_csv\')" value="" style="width:59px; height:17px; background:url(images/button-importstart.png) repeat-x left center;border:0;margin-left:0px; float:center;" />

Php page inserttodbb.php :

if(isset($_GET['fonction']) and $_GET['fonction']=="import_csv_valid")
{


$data=$_SESSION['listeok'];
    $count=count($data);

foreach($data as $numero)
{

    $req=("INSERT INTO contact VALUES('".$idclient."','', '".$numero."','','','','','','','0')");   
    $doins = mysql_query($req) or die(mysql_error()); 
}
echo 'Import OK for '.$count.' number !';


}

I have not the problem of time out when I load the php page. But when I try to use the ajax loader I have a problem with the message "Error occured during requesting the page". I tryed to put the timeout to 900000 but the problem continue. An idea ?

function makeRequest(url){
    $('#preloader').show();
    $.ajax({
        type: "GET",
        url: url,            
        timeout: 9000000,  //10 seconds, define this value in milliseconds
        success: function(data){
            $('#resultDiv').html(data);
            $('#preloader').hide();
        },
        error: function() {
            alert( 'Error occured during requesting the pagesssssss' );
            $('#preloader').hide();
        }
    });
    }
  • 写回答

3条回答 默认 最新

  • drgc9632 2014-02-11 15:22
    关注

    If the timeout is in the ajax call (not the PHP script) you can use this:

    function makeRequest(url){
            $('#preloader').show();
            $.ajax({
                type: "GET",
                url: url,            
                timeout: 10000,  //10 seconds, define this value in milliseconds
                success: function(data){
                    $('#resultDiv').html(data);
                    $('#preloader').hide();
                },
                error: function() {
                    alert( 'Error occured during requesting the page' );
                    $('#preloader').hide();
                }
            });
    }
    

    EDIT:

    Another option is to define a global timeout value. Put this in your code BEFORE calling makeRequest().

    $.ajaxSetup({
        timeout:10000 // 10 seconds
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥50 安装华大九天aether
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)