小编典典
最后,我只是将参数添加到Route :: get()以及ajax url调用中。我在getAjax()函数中将$ _POST [‘id’]更改为$ _GET
[‘id’],这使我的回复
Route::get('testUrl/{id}', 'TestController@getAjax');
$(function(){
$('#button').click(function() {
$.ajax({
url: 'testUrl/{id}',
type: 'GET',
data: { id: 1 },
success: function(response)
{
$('#something').html(response);
}
});
});
});
TestController.php
public function getAjax()
{
$id = $_GET['id'];
$test = new TestModel();
$result = $test->getData($id);
foreach($result as $row)
{
$html =
'
' . $row->name . '' .'
' . $row->address . '' .'
' . $row->age . '' .'
';}
return $html;
}
2020-07-26