Hi and thanks for helping me, I have a ajax call with data I would like to send to the Controller so I can delete the specified data at a later time. For the moment I would like to show the given javascript from the controller. Sorry in advance for my English, it's not my first language.
It's currently returning a JsonResponse to test if the method is called but I want to return the given javascript array (playlogs) instead, how can I do that?
Javascript:
<script type="text/javascript">
$(document).ready(function () {
$('#deleteBtn').click(function () {
var playlogs = [];
$.each($("input[name='playlog']:checked"), function () {
playlogs.push($(this).val());
});
var confirmText = "Are you sure you want to delete this?";
if (confirm(confirmText)) {
$.ajax({
type: "delete",
url: '{{ path('playlog_delete_bulk') }}',
data: playlogs,
success: function () {
alert("selected playlogs: " + playlogs.join(", "));
},
});
}
return false;
});
});
</script>
deleteBulkAction in PlayLogController:
/**
* @Route("/delete/bulk", name="playlog_delete_bulk")
*/
public function deleteBulkAction(Request $request)
{
if ($request->isXMLHttpRequest()) {
return new JsonResponse(array('data' => 'Successfully called the named route playlog_delete_bulk '));
}
return new Response('This is not ajax!', 400);
}