0

UPDATED QUESTION


Let i have a blank page with only a simple ajax request as follow

My Ajax Call is

$.ajax({
    url: "ajax/ajax-latest-lead.php",
    method: "POST",
    data: {
        cityVal: cityVal
    },
    cache: false,
    async: true,
    timeout: 2000, //Set your timeout value in milliseconds or 0 for unlimited
    success: function(data) {
        alert(data);
    },
    error: function(jqXHR, textStatus, errorThrown) {
        if (textStatus === "timeout") {
            alert("Call has timed out"); //Handle the timeout
        } else {
            alert("Another error was returned"); //Handle other error type
        }
    }
});

It will Always Going to Call has timed out.and waiting time is 2.0 Seconds in mozila firefox->network tab

And A Php File is as follow

<?php
include("../include/database.php");
if(!empty($_POST['cityVal']))
{
    $cityVal = $_POST['cityVal'];
    echo $cityVal;
}
?>

Problem is When i am including Database file The Response time of ajax is 3.0 seconds. and when i am excluding database file alert(data) runs immediately.

Database.php

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$conn = new mysqli("$host","$username","$password","$db_name");

I tried Followings

e.preventDefault();
cache: false,
async: false,
beforeSend:function(data){ 
 alert("sending");
},

Before Send Alert Will be shown immediately

I am stuck here very badly. please help to find this out.

TarangP
  • 2,711
  • 5
  • 20
  • 41
  • The database connection is causing that delay. Ensure the connectivity between servers are fast. – Aefits Feb 26 '18 at 13:23
  • ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 26 '18 at 13:40
  • 1
    Please do not repost questions. – Jay Blanchard Feb 26 '18 at 13:40
  • Please, [quit using `alert()` for troubleshooting.](http://stravid.com/en/stop-the-javascript-alert-madness/), use `console.log()` instead. – Jay Blanchard Feb 26 '18 at 13:40
  • It's not An Answer. And this question isn't answered on my last question. you cant close this question. last question is not a proper solution. it works only for modal. @JayBlanchard And I am not using PHP 7 I am using PHP Version 5.4.31 –  Feb 27 '18 at 06:03

0 Answers0