1
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(){
}
});
});
will be used to update a register in the database, however I will need it to send the POST
and also the id
for var id
, there is some way data:
returns the form, id
? thanks!
EDITED
On the server side I have an update method, which will receive $_POST in the variable $params
I wanted to receive the id
separate from the $_POST
for me to pass the second parameter of the method, I tried to get the id together with $_POST but it didn’t 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;
}
When you say "the captured id" you mean to
var id = $(this).attr("id");
?– Sergio
Either the question is wrong, or I don’t understand. The parameter
data
does not return anything, just sends. What returns is thejson
, and in it, you can return whatever you want, in the script that runs in/updateClient
.– Rene Freak
Exactly "send", and yes the id captured in
var id
.– wDrik
Can you explain what kind of information you send and what you need to know about the server? Do you already have any server part code?
– Sergio
I updated the question see if I can be more specific.
– wDrik
You could change the url so that it contains the id, updateClient/21, for example, and on the server get the url id.
– luislhl