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

超时 - 在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条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型