Post to server passing variable

Post to server passing variable

Chip HeadChip Head Posts: 2Questions: 0Answers: 0
edited March 2011 in General
Hope somebody can help me with this. Have searched the forum for a day looking for an answer or a clue! The following code has a very simple task, remove a record from the server-side database. If I hard-code the id number into the $.post statement it works, but not with a variable (aID) containing the same value. I have put trace code for aID before and after the $.post statement, so I know the value is correct.

[code]
$(document).ready(function() {
$('#example tbody td').click( function () {
var aCol = oTable.fnGetPosition( this )[1];
var aRow = oTable.fnGetPosition( this )[0];
var aPos = oTable.fnGetPosition( this );
var aID = array_id[aRow];

if ( aCol == 0 ) {
oTable.fnDeleteRow( aRow );
$.post('tasksdelete.php', { "id": aID } );
} else {
aData = oTable.fnGetData( aPos[0] );
}

} );
} );
[/code]

Any help would be greatly appreciated!

Replies

  • Chip HeadChip Head Posts: 2Questions: 0Answers: 0
    SOLVED!

    After some more playing around, this works! Column five is hidden and contains the record ID.

    [code]
    $(document).ready(function() {
    $('#example tbody td').click( function () {
    var aCol = oTable.fnGetPosition( this )[1];
    var aRow = oTable.fnGetPosition( this )[0];
    var aPos = oTable.fnGetPosition( this );

    if ( aCol == 0 ) {
    $.ajax({
    type: "POST",
    url: "tasksdelete.php",
    data: ( {id : oTable.fnGetData(aRow)[5]} )
    });

    oTable.fnDeleteRow( aRow );
    } else {
    aData = oTable.fnGetData( aPos[0] );
    }

    } );
    } );
    [/code]

    Maybe this will help somebody else.
This discussion has been closed.