jquery - Ajax, PHP, and mysqli -
dudwhen call php file using ajax, takes full 30 seconds before results displayed.
how make results more instantaneous?
my ajax is:
$("#j_search").keyup(function(){ if(($.trim($(this).val()) != '') & ($(this).val() != ' ')){ $.post('../php/ajax/j_search.php', {search: $(this).val()}, function(data){ $(".matched_results").html(data).show(); }); } });
if reason think php wrong, write sample of own , test that, though doubt it. can not give php source code.
i fired releasing code seems worth @ times these.. here snippet of php:
class sql_commands{ //connecting vars private $_host = "localhost"; private $_user = "root"; private $_pass = "dud"; private function handle($errornum, $errormsg){//used error handler $handle = new handle(); $handle->direct($errornum, $errormsg); } function connect($db){ $con=mysqli_connect($this->_host,$this->_user,$this->_pass,$db); if (mysqli_connect_errno($con)){ $this->handle("001","connection failed (db)"); } return $con; // mysqli_close($con); //$sql_commands->connect("db"); } function sql($db, $sql){//construct used transact connect return mysqli_query($this->connect($db), $sql); // mysqli_close($this->connect($db)); //$sql_commands->sql("db", "select * table id=1"); } function assoc_grab($db, $sql, $arraygrab){//returns data associated array directed query $data = array(); $row = mysqli_fetch_assoc($this->sql($db, $sql)); foreach($arraygrab $pointer){ array_push($data,$row[$pointer]); } //print_r($sql_commands->assoc_grab('db', "select * table id='1'", array('name'))); return $data; } }
there's nothing incorrect javascript code wrote. it's problem either php, or server you're using.
try replace php (i.e.: php/ajax/j_search.php) simple code one:
<?php echo rand(); ?>
now every time press key while focus on "#j_search" textbox should see instantaneously new random number. if still taking while, might need check server. try restart machine, might solve problem!
edit1: check answer: wamp/xampp responding slow on localhost
edit2: try change line in provided php code:
private $_host = "localhost";
with:
private $_host = "127.0.0.1";
Comments
Post a Comment