我该如何将此ajax调用中的id传递给TestController的getAjax()函数?当我进行调用时,url为testUrl?id=1
Route::get('testUrl', 'TestController@getAjax');
<script>
$(function(){
$('#button').click(function() {
$.ajax({
url: 'testUrl',
type: 'GET',
data: { id: 1 },
success: function(response)
{
$('#something').html(response);
}
});
});
});
</script>
测试控制器.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;
}
$id = $_GET['id'];
我使用了Input::get("id")
,无论如何都有效,非常感谢。 - Vipertecpro