cannot make ajax.data work

cannot make ajax.data work

OscarCOscarC Posts: 19Questions: 5Answers: 0

I have a straight forward table with this initialization:

 $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url:"/php/alerts.php",
            type: "POST",
            data: {
                 "USERID": "841"
            }
        },
        columns: [
            { data: "OBJECTID" },
            { data: "SPECIES"},
            { data: "STATEFIPS"},
        { data: "COUNTYFIPS"}
        ],
        select: true
    } );
})

that goes to a serverside script that has the same fields, plus an USERID field

Editor::inst( $db, 'MISIN_ALERTS', 'OBJECTID' )
    ->fields(
        Field::inst( 'OBJECTID' ),
        Field::inst( 'ALERTID' ),
        Field::inst( 'USERID' ),
        Field::inst( 'SPECIES' ),
        Field::inst( 'STATEFIPS' ),
        Field::inst( 'COUNTYFIPS' )
    )

I want ajax.data to pas the USERID value to select only the rows where USERID = something
I cannot make it work.
If I go to the server side script and I add a ->where('USERID','123') everything works fine
What am I doing wrong in the ajax.data?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,994Questions: 1Answers: 10,368 Site admin
    Answer ✓

    Where you using the following?:

    ->where( 'USERID', $_POST['USERID'] )
    

    If not, what were you using?

    Allan

  • OscarCOscarC Posts: 19Questions: 5Answers: 0

    ah!! I was using

    ->where( 'USERID', data.USERID )
    

    and when it didn't work, was looking for all kinds of permutations with ajax.data.USERID. In hindsight it looks pretty dumb and what you wrote makes perfect sense, and worked perfectly at the first try.

    I would say that I did not find any examples of serverside scripts on that particular ->where situation.

    Thank you very much.

This discussion has been closed.