I want to get the id_user data based on the desired row table by doing onclick jquery, then the id_user data can be passed to the controller and redirect page to edit_user, how do I get the id_user data with onclick using the jquery function? I beg for your help, sorry if any of my questions are unclear, if unclear, you can ask me
This is my code
function edit(){
var id_user = $(this).attr("id_user");
var url = $(this).attr("href");
alert(id_user);
console.log(id_user);
$.ajax({
type:'post',
url : url,
data :{id_user:id_user},
success:function(data){
alert(data)
},
error:function(err){
alert(err)
}
});
}
This is my code
<a onclick="edit()" id_user="<?php echo $row ['idx'] ?>" href="<?php echo BASE_URL. 'app.php/usermanagement/edit_user' ?>" class="edit">Edit</a>
This is my controller
public function edit(){
Template::setTitle('Edit User Management');
$id_user =(int)Request::post('id_user');
//$id_user = (int)$_POST['id_user'];
echo $id_user; die;
//$id_user = (int)Session::get('idx');
$result = $this->getUserbyId($id_user);
$dataresult = json_decode($result, true);
if($dataresult === NULL) {
echo "<script language = \"javascript\">window.alert(\No Have Data\");";
echo "javascript:history.back();</script>";
return false;
}
$data = $dataresult;
return $data;
This is my controller code for function getUserbyId
public function getUserbyId($id_user){
//$id_user = Request::post('id_user');
echo json_encode($id_user);
if(!empty($id_user)){
$url="http://localhost:8585/get-user/$id_user";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if($result === FALSE){
die('Curl failed: ' .curl_error($curl));
}
curl_close($curl);
return $result;
}
}
my problem is
id_user undetified