【问题标题】:ajax taking too much time for loadingajax 加载时间过长
【发布时间】:2015-01-06 12:17:34
【问题描述】:

ajax 调用需要很长时间来加载。在调用 data.php 将数据存储在数据库中之后,我们将数据保存在 info_arr 变量中。

脚本代码

function insert_init_cookie(isclosed){
    if(!checkCookie('__utma')){
        setCookie('__utma', hash('<?=$domain?>')+'..'+getUniqueId()+'..'+'<?=$unixtime?>'+'..'+'<?=$unixtime?>'+'..'+'<?=$sess_id?>'+'..'+'<?=$sc?>', 0, '/', '<?=$domain?>',false);
    }
    if(!checkCookie('__Idletime')){
        setCookie('__Idletime',idleTime, 3, '/', '',false);
    }
    var StrCaVal = readCookie('__JDutma') ;
    var dn = '<?=$domain?>';
    var ca = encodeURIComponent(StrCaVal);

    var info_arr = '<?= json_encode($trace_info)?>';
    $.ajax({
        type : "POST", 
        async: false,
        url  : WEBROOT+"cookies/data.php",                  
        data : {
        dn : dn,
        bclosed:isclosed,
        ca : ca,
        info_arr : info_arr,
        },  

    });
 }

用于在数据库data.php代码中插入数据

<?php
session_start();
ob_start();

$pst_data = json_decode(stripslashes($_POST['info_arr']));
$trace_info = json_decode(json_encode($pst_data),true);
$dn = $_POST['dn'];
$ca = $_POST['ca'];
$bclosed = $_POST['bclosed'];
$StrTrackVal = $_POST['StrTrackVal'];
$strca= urldecode($ca);
$strcc= urldecode($cc);
$strca = explode("..",$strca);
$StrTrackVal = explode("..",$StrTrackVal);
global $rt_con,$comp_con;
$comp_con=mysql_connect('9.2.0.203','123','123') or die('error');# connection of  
   $sql_check = "SELECT uniquevisitorid FROM analytics_staging.tbl_analytics_data WHERE uniquevisitorid = '".$strca[1]."'";
    $analycz = mysql_query($sql_check,$comp_con);
    if(mysql_num_rows($analycz)<1){
        $unix_start_time = strtotime(date('jS F Y h:i:s A (T)'));
        $unix_end_time   = '';
    }else{
        $unix_start_time = strtotime(date('jS F Y h:i:s A (T)'));
        $unix_end_time = $unix_start_time;

        $update_analycz="UPDATE analytics_staging.tbl_analytics_data  SET unixtimestamp_end = '".$unix_start_time."' WHERE uniquevisitorid='".$strca[1]."'  ORDER BY id DESC LIMIT 1;";
        $result = mysql_query($update_analycz,$comp_con);



    }
    if(empty($bclosed))
$insert_into_analycz="INSERT INTO analytics_staging.tbl_analytics_data  (cookiename,domainhash,uniquevisitorid,unixtimestamp_start,unixtimestamp_end,sessionid,session_counter,referral,path,domainname,userip,country,city,browser,useros,querystring,http_host,http_user_agent,inserttime) values('','".$strca[0]."','".$strca[1]."','".$unix_start_time."','','".$trace_info['session_id']."','".$trace_info['sc']."','".$trace_info['referer']."','".$trace_info['path']."','".$dn."','".$trace_info['user_ip']."','".$trace_info['UserCountry']."','".$trace_info['UserCity']."','".$trace_info['UserBrower']."','".$trace_info['UserOS']."','".$trace_info['UserQuery_String']."','".$trace_info['JDHTTP_HOST']."','".$trace_info['user_agent']."',now())";
$result_analycz = mysql_query($insert_into_analycz,$comp_con);

?>

我如何最小化加载时间?因为这个网站的其他功能受到影响

【问题讨论】:

    标签: ajax


    【解决方案1】:

    试试这个:只需将 async: false, 更改为 async: true, 即可完美运行..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 2016-06-20
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      相关资源
      最近更新 更多