1

I am stuck inside a problem I cannot handle easily. I have create some fields (input and select) without using the <form> tag. When the user click on the "Research" button starts the following script:

  • get all the value from the fields,
  • send all the fields to a Php page, using the DATATABLES plugin. Here is the code:

    function assetSearch() {

    var validation = checkForSelectedFields();

        if (validation == "KO")
            return;
    
            var arrForm = [];
      arrForm.push(document.getElementById("name").value);
        arrForm.push(document.getElementById("idConfig").value);
      arrForm.push(document.getElementById("serialNumber").value);
      arrForm.push(document.getElementById("tipo").value);
      arrForm.push(document.getElementById("ambiente").value);
      arrForm.push(document.getElementById("modello").value);
      arrForm.push(document.getElementById("locazione").value);
      arrForm.push(document.getElementById("vendor").value);
        arrForm.push(document.getElementById("gruppo").value);
        arrForm.push(document.getElementById("stato").value);
      arrForm.push(document.getElementById("classe").value);
      arrForm.push(document.getElementById("securityLevel").value);
        arrForm.push(document.getElementById("aggregatore").value);
    
            console.log(JSON.stringify(arrForm));
    
            var outcomeResearchTable = document.getElementById("OUTCOME_RESEARCH_TABLE");
    
      outcomeResearchTable.style.display = "flex";
    
     $('#OUTCOME_RESEARCH_TABLE').DataTable( {
    //    "ajax": {
    //        "url": "asset_GestAsset.php",
      //      "type": "POST",
        //    "data": function(d) {
                    //      d.form = $("#researchForm").serializeArray();
                    //  }
        //},
        "paging": true,
        "processing": true,
                "ajax": "asset_GestAsset.php",
        "deferLoading": 57,
        "deferRender": true,
        "scrollY": 350,
        "scrollX": true,
        "bRetrieve": true,
        "bDestroy": true,
        "iDisplayLength": 100,
        "ordering": false,
        "info":     true,
        "sDom":     'ltipr',
        "order": [[1, 'asc']]
      } );
    

    }

non at all the fields are mandatory but at least one text input has to be compiled. The point is that Datatables, using the code shown previously, send me back an error: DataTables warning: table id=OUTCOME_RESEARCH_TABLE - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Just for test, I decided to try the query and show the values on the Datatable, so I decided to don't care about the Ajax problem but another the problem has come: Php tells me "OUT OF MEMORY". Looking at Google Developer Console I have been informed that under the column: STATUS (inside Network) the php page is in "pending" for about 30seconds and the error is:

Fatal error: Out of memory (allocated 559939584) (tried to allocate 25165832 bytes) in

<?php

ini_set('memory_limit', '-1');
include("function.php");

$conn = connectionDB();

$queryOriginale = " select  A.ID_CONFIG IDCONF, A.ID_ASSET IDASSET, A.NOME NOME,B.SERIAL_NUMBER SERIALNUMBER, B.TIPO TIPOLOGIA, C.DESCRIZIONE STATO, E.NOME AGGREGATORE,
                                      F.ID_CED,F.SALA,F.FILA,F.POSIZIONE,D.NOME AMBIENTE , H.NOME MODELLO, G.DESCRIZIONE NOMECED, 'n/a' CONTRATTO, A.VALIDA_DAL VALIDADAL,A.VALIDA_AL VALIDAAL
                                      from
                                      PCMDB_INV.ASSET B, PCMDB_INV.CONFIG A, PCMDB_INV.STATO C, PCMDB_INV.AMBIENTE D,
                                      PCMDB_INV.AGGREGATOR E, PCMDB_INV.LOCAZIONE F, PCMDB_INV.CED G, PCMDB_INV.MODELLO H,
                                      PCMDB_INV.SOFTWARE L, PCMDB_INV.SW_CONFIG O, PCMDB_INV.GRUPPO M, PCMDB_INV.TECH_APPLICATION N,
                                      PCMDB_INV.SECURITY_LEVEL P, PCMDB_INV.SEC_LEVEL_CONFIG Q";

$SSS = oci_parse($conn, $queryOriginale);
oci_execute($SSS);
$NUM = oci_fetch_all($SSS, $res);


$stid = oci_parse($conn, $queryOriginale);
oci_execute($stid);

$i = 0;
echo "{ \"aaData\": [\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    $i++;

        $a = trim($row["IDCONF"]);
        $b = trim($row["NOME"]);
        $c = trim($row["TIPOLOGIA"]);
        $d = trim($row["STATO"]);
        $e = trim($row["AMBIENTE"]);
        $f = trim($row["AGGREGATORE"]);
        $f2 = trim($row["NOMECED"]);
        $g = trim($row["MODELLO"]);
            $h = trim($row["CONTRATTO"]);
            $l = trim($row["VALIDADAL"]);
            $m = trim($row["VALIDAAL"]);

    if ($i < $NUM){
        echo "[ \"".$a."\", \"".$b."\", \"".$c."\", \"".$d."\", \"".$e."\", \"".$f."\", \"".$f2."\", \"".$g."\", \"".$h."\", \"".$l."\", \"".$m."\" ], \n";
    }else {
        echo "[ \"".$a."\", \"".$b."\", \"".$c."\", \"".$d."\", \"".$e."\", \"".$f."\", \"".$f2."\", \"".$g."\", \"".$h."\", \"".$l."\", \"".$m."\" ]\n";
    }
}
echo "] }";
?>

Someone could help me to solve both of the problems? Many thanks in advance

1 Answer 1

1

while (($row = oci_fetch_array($stid, OCI_BOTH)) != false) {

this should help with the "out of memory" problem.

additional information: (think about it)

native js:

var form = document.querySelector('form');
var data = new FormData(form);
var req = new XMLHttpRequest();
req.send(data);

reference

jQuery:

$( "form" ).on( "submit", function( event ) {
  event.preventDefault();
  console.log( $( this ).serialize() );
});

reference

have a nice one

Sign up to request clarification or add additional context in comments.

2 Comments

Using OCI_BOTH and != false helped me reducing the time from 30seconds to less (I still receive the error: Fatal error: Out of memory (allocated 251658240) (tried to allocate 12582920 bytes) in C:\xampp\htdocs\\asset_GestAsset.php on line 18 )
Second, your suggestions doesn't consider how to deal with the DataTable. Anyway thank you for your tips! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.