I have the following script:
('#AjaxUpdateClient').submit(function(e){
var id = $(this).attr("id");
var form = $(this).serialize();
$.ajax({
type: "POST",
url: "/updateClient",
data: form,
dataType: "json",
success: function(){
}
});
});
It will be used to update a database in the database, but I'll need it to send POST
and also id
to var id
, is there any way that data:
returns form, id
? Thanks!
EDITED
On the server side I have an update method, which will get the $ _POST in the variable $params
I wanted to receive the id
separated from the $_POST
so I pass the second method parameter, tried to receive the id next to the $ _POST but it did not work ..
//Update on database
public function update($params, $id)
{
$params_fields = "'".implode("'= ?, '", array_keys($params))."'= ?";
$query = "UPDATE '{$this->table}' SET {$params_fields} WHERE 'id'= ?";
$stmt = $this->db->prepare($query);
$i=1;
foreach($params as $key => $value){
$stmt->bindValue($i, $value);
$i++;
}
$stmt->bindValue($i, $id);
$stmt->execute();
return $stmt;
}