Hi, im trying to do a ajax live search. It work`s, but i want it to be fast. Currently i`m processing the html by php, but even if i change the processing to js and only get the data from php it only improves my search from 2.1 to 1.8 seconds (this is the request time, but it takes 4/5 seconds for the data to appear)
Heres my code:
$("#searchfield").change(function() {
    term = $(this).val();
    if (searchReq != false) {
    searchReq.abort();
    }
    searchReq = $.get("/searchModal.php", {
        term : term
    }).done(function(data) {
        $("#liveSearch").html(data);
    });
});
EDIT:
php code:
search.php:
$files = filecontroller::search($term);
file controller:
public static function search($term, $by = false, $order = false) {
    connection::connect();
    $files = ($by && $order && validation::filesOrder($by, $order)) ? file::Search($term, $by, $order) : file::Search($term);
    return $files;
}
File model:
public static function Search($term, $by = 'date', $order = 'DESC') {
    $session_id = $_SESSION["user_id"];
    $term = mysql_real_escape_string($term);
    $query = mysql_query("SELECT * FROM files WHERE idUser = '$session_id' AND (name LIKE '%$term%' OR description LIKE '%$term%') ORDER BY $by $order");
    $files = self::CreateFromDb($query);
    return $files;
}
private static function CreateFromDb($query) {
    GLOBAL $imgDir; // just get the img dir from a config file
    GLOBAL $userDir; // same
    $files = array();
    while ($row = mysql_fetch_assoc($query)) {
        $file = new File();
        $file -> type = $row['type'];
        $file -> idFile = $row['idFile'];
        $file -> user = $row['idUser'];
        $file -> gallery = $row['idGallery'];
        $file -> name = htmlspecialchars($row['name']);
        $file -> description = htmlspecialchars($row['description']);
        $file -> date = $file -> timecheck($row['date']);
        $file -> size['kb'] = $row['size'];
        $file -> galleryName = Gallery::getName($file -> gallery);
        $files[] = $file;
    }
    return $files;
}
Is there anyway to improve it? Im testing in local.
 
     
    