Reputation: 11
ajax call taking to much time for loading.we saved data in info_arr variable after that calling data.php for storing data in database.
Script code
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,
},
});
}
for inserting data in databse data.php code
<?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);
?>
how i minimize the loading time?because of this website other functionality affected
Upvotes: 1
Views: 2054
Reputation: 3299
Try this: Just change from async: false,
to async: true,
it may work perfectly..
Upvotes: 1