Jak przekazać identyfikator z tego wywołania ajax do funkcji getAjax() kontrolera TestController? Kiedy zrobić wywołanie URL jest testUrl? Metoda id = 1Laravel przekazanie danych za pomocą ajax do kontrolera
Route::get('testUrl', '[email protected]');
<script>
$(function(){
$('#button').click(function() {
$.ajax({
url: 'testUrl',
type: 'GET',
data: { id: 1 },
success: function(response)
{
$('#something').html(response);
}
});
});
});
</script>
TestController.php
public function getAjax()
{
$id = $_POST['id'];
$test = new TestModel();
$result = $test->getData($id);
foreach($result as $row)
{
$html =
'<tr>
<td>' . $row->name . '</td>' .
'<td>' . $row->address . '</td>' .
'<td>' . $row->age . '</td>' .
'</tr>';
}
return $html;
}
Nie muszę określić trasę dla adresu url w wywołaniu $ .ajax? – learntosucceed
$ .ajax lub $ .post jest takie samo w tym przypadku –