This is my ajax request and i'm trying to pass those values into a controller in laravel
var deviceid="<?php echo $id; ?>";
var day="<?php echo $day; ?>";
$.ajax({
'async': false,
'global': false,
url: '/location/show/getLocation/{id}/{date}',
dataType: 'json',
type: 'GET',
data: { id:deviceid,date:day},
success:function(data){
myVariable=data;
console.log(data);
}
});
In my controller i got these values as
$id=$_GET['id'];
$date =$_GET['date'];
echo $id.$date;
But values doesn't show in console can anyone tell me the issue??
edited code
view
<script>
var deviceid="<?php echo $id; ?>";
var day ="<?php echo $day; ?>";
// console.log(deviceid,day);
$.ajax({
'async': false,
'global': false,
url: '/location/show/getLocation',
dataType: 'json',
type: 'POST',
data: { id:deviceid,date:day},
success:function(data){
console.log(data);
}
});
</script>
controller
public function getLocation(Request $request)
{
$id=$request->input('id');
$date=$request->input('date');
echo $id;
echo $date; exit;
}
route
Route::post('location/show/getLocation', 'DemoController@getLocation');
url: '/location/show/getLocation/' + deviceid + '/' + day, And you do not need thedatakey in this case.