0
如何在ajax成功中显示我的结果,因此它显示返回结果并且不重新加载页面。如何在ajax请求后显示结果
这是我的脚本---
<script>
$(document).ready(function() {
$("#searchform").on('submit', function (e) {
$.ajax({
url: '/home',
type: 'post',
data: {contentSearch: $('#contentSearch').val()},
success: function (data) {
$('table.my-data-table').dataTable({}) // the table
// here i want to show the result
// how can i show the result here
// i am passing the result as result in the twig file
}
});
return false;
});
});
</script>
控制器我发送的结果像“结果” => $结果
return $this->render('AdminBundle:Home:home.html.twig', array(
'pageTitle' => 'my ajax',
'result' => $result // result sending to twig file
)
所以,我怎么能显示通过Ajax的结果任何人都知道如何解决这个问题。
非常感谢。
如果您要更换整个页面,'$(document.body的).html(data);'(例如,使用选择器替换一个部分)然后你可以在表上调用'.dataTable'。 –
@TylerSebastian我不想替换整个页面,我只是想在表格或某处显示结果,所以整个页面不需要替换我猜,只有表格中的值需要替换 –