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条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题