Dynamic Update with ajax

1

I researched and still could not solve this problem. is an onclick event that sends a request to the update.php file, which makes an update to the notifications table. Here is the code below:

Triggers the onclick event:

<input type="hidden" name="id" id="id" value="'.$id.'">

<a onclick="sendData()" href="#">

Ajax from this page:

<script>
function sendData()
{
    var id_n = $('#id').val();

    $.ajax({
        type:"POST",
        url:"update.php",
        data: { id: id_n },
        contentType: false,
        cache: false,
        processData: false,
        success:function(dta)
        {
            alert(dta);
        }

    });
}

</script>

Excerpt from update.php file, code:

$id = ($_POST['id']);
$sql = "UPDATE notif SET status = 1 WHERE id = :id";
$res = $pdo->prepare($sql);
$res->bindParam(':id',$id);
$res->execute();
$pdo->close(); 

What could be wrong? Thankful for attention.

    
asked by anonymous 17.11.2016 / 21:50

1 answer

0

When you pass an object as { id: id_n }, to data of ajax, what jQuery does is convert query string: id=oValorDe_id_n to jQuery.param () . Having the processData: false option prevents it. Removing it assumes processData: true .

You can read more about it here

    
17.11.2016 / 22:20