Server-side "Processing..." freeze

Server-side "Processing..." freeze

SpringlottSpringlott Posts: 2Questions: 0Answers: 0

Hi everyone,

I have an issue with my server-side processing. I check the validity of my JSON with https://jsonlint.com/ and my JSON is valid but the table stay freeze with "Processing ..." cf. picture

Here is my JS:

    $(document).ready(function() {
        $('#resultTable').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": "datatable_processing.php",
        });
    });

Here is my php:

<?php
// Create connection to the db
$connexion = connexion_sql("Interactomiq_test");
if ($connexion->connect_error) {
    redirect_result(array($connexion->connect_error), true);
}

$phpTable = array();
$mainQuery = "SELECT * FROM ResultsExp WHERE ResultsExp.id_kojak=(SELECT IFNULL(MAX(id_kojak), 0) AS id_ FROM KojakParameter)";
$mainAnswer = $connexion->query($mainQuery) or die($connexion->error);

while ($mainRow = $mainAnswer->fetch_assoc()) {
    $phpRow = array($mainRow["scan"], $mainRow["ret_time"], $mainRow["intensity"]);

    if ($mainRow["id_crosslink"] != null) {
        $idXlink = $mainRow["id_crosslink"]; 
        $xlinkRow = get_answer($connexion, "SELECT * FROM CrossLink WHERE CrossLink.id_crosslink=$idXlink");
        
        $idF1 = $xlinkRow["id_frag_1"];
        $f1Row = get_answer($connexion, "SELECT * FROM Fragments WHERE Fragments.id_fragment=$idF1");
        $idProt1 = $f1Row["id_prot"];
        $protein1 = get_answer($connexion, "SELECT * FROM Proteins WHERE Proteins.id_prot=$idProt1");
        $sequence1 = get_fragment_sequence($protein1, $f1Row);
        
        $idF2 = $xlinkRow["id_frag_2"];
        $f2Row = get_answer($connexion, "SELECT * FROM Fragments WHERE Fragments.id_fragment=$idF2");
        $idProt2 = $f2Row["id_prot"];
        $protein2 = get_answer($connexion, "SELECT * FROM Proteins WHERE Proteins.id_prot=$idProt2");
        $sequence2 = get_fragment_sequence($protein2, $f2Row);
        
        $phpRow = array_merge($phpRow, array($xlinkRow["mass_obs"], $xlinkRow["charge"], $xlinkRow["mass_psm"], $xlinkRow["ppm_error"], $xlinkRow["score_tot"],
            $xlinkRow["e_value"], $xlinkRow["score_pep1"], $xlinkRow["e_value_pep1"], $sequence1, get_site($xlinkRow["site_1"],$sequence1), $protein1["name"], $xlinkRow["score_pep2"],
            $xlinkRow["e_value_pep2"], $sequence2, get_site($xlinkRow["site_2"],$sequence2), $protein2["name"]));
    } else {
        $idF1 = $mainRow["id_fragment"];
        $f1Row = get_answer($connexion, "SELECT * FROM Fragments WHERE Fragments.id_fragment=$idF1");
        $idProt1 = $f1Row["id_prot"];
        $protein1 = get_answer($connexion, "SELECT * FROM Proteins WHERE Proteins.id_prot=$idProt1");
        $sequence1 = get_fragment_sequence($protein1, $f1Row);

        $phpRow = array_merge($phpRow, array("-", "-", "-", "-", "-", "-", "-", "-", $sequence1, "-", $protein1["name"], "-", "-", "-", "-", "-"));
    }
    
    $phpRow = array_merge($phpRow, array($mainRow["date_exp"]));
    array_push($phpTable, $phpRow);
}

echo json_encode($phpTable, JSON_FORCE_OBJECT);
$connexion->close();

<?php
>
```
?>


By launching this php only I obtained the following JSON:

{
"0": {
"0": "20",
"1": "2",
"2": "0",
"3": "301",
"4": "1",
"5": "300",
"6": "0",
"7": "2",
"8": "13",
"9": "1",
"10": "5",
"11": "MRTFDK",
"12": "T2",
"13": "PA0001",
"14": "1",
"15": "8",
"16": "PEISRLLVAQK",
"17": "S3",
"18": "PA0001",
"19": "2019-11-02"
},
"1": {
"0": "24",
"1": "2",
"2": "0",
"3": "395",
"4": "1",
"5": "394",
"6": "0",
"7": "2",
"8": "8",
"9": "1",
"10": "19",
"11": "LRRAQEREQT",
"12": "A3",
"13": "PA0001",
"14": "1",
"15": "49",
"16": "DEIIFMFHNK",
"17": "I2",
"18": "PA0002",
"19": "2019-11-02"
}
}
```

Anyone has an idea of what is wrong ? Thank you by advance

Replies

  • kthorngrenkthorngren Posts: 21,144Questions: 26Answers: 4,918
    edited April 2019

    Although your data is a valid JSON string it is not in a structure that Datatables supports. This doc explains the supported structures:
    https://datatables.net/manual/data/#Data-source-types

    Essentially the data needs to be an array of rows. The rows can be made up of either array data or object data. You would need something more like this:

    [
        {
            "0": "20",
            "1": "2",
            "2": "0",
            "3": "301",
            "4": "1",
            "5": "300",
            "6": "0",
            "7": "2",
            "8": "13",
            "9": "1",
            "10": "5",
            "11": "MRTFDK",
            "12": "T2",
            "13": "PA0001",
            "14": "1",
            "15": "8",
            "16": "PEISRLLVAQK",
            "17": "S3",
            "18": "PA0001",
            "19": "2019-11-02"
        },
        {
            "0": "24",
            "1": "2",
            "2": "0",
            "3": "395",
            "4": "1",
            "5": "394",
            "6": "0",
            "7": "2",
            "8": "8",
            "9": "1",
            "10": "19",
            "11": "LRRAQEREQT",
            "12": "A3",
            "13": "PA0001",
            "14": "1",
            "15": "49",
            "16": "DEIIFMFHNK",
            "17": "I2",
            "18": "PA0002",
            "19": "2019-11-02"
        }
    ]
    

    Secondly since you are using server side processing there are more requirements on the returned data as described here:
    https://datatables.net/manual/server-side

    Your rows will need to be in a data object along with returning the other parameters described in the returned data section.

    Kevin

  • SpringlottSpringlott Posts: 2Questions: 0Answers: 0

    Thank you for your help Kevin

This discussion has been closed.