I'm trying to get a simple AJAX request to work in Symfony2. It seems that the request is never reaching the controller. Instead of alerting "ajax ok', the AJAX request returns the HTML of the localhost page (wamserver). it is erver Configuration Apache Version : 2.4.9 - Documentation PHP Version : 5.5.12 - Documentation Server Software: Apache/2.4.9 (Win64) PHP/5.5.12 Loaded Extensions : apache2handlerbcmath.............................................
public function indexAction(Request $request)
{
if (!$request->isXmlHttpRequest()) {
return $this->render(
'UsuarioBundle:Default:index.html.twig'
);
} else {
return new Response("Ajax ok");
}
}
jquery:
$(function(){
var data={
type:'1'
};
var i = 0;
$(window).scroll(function(){
//cuando llegas al final de la página
if (document.body.scrollHeight - $(this).scrollTop() <= $(this).height()){
agregarContenido();
}
});
function agregarContenido(){
//Agregar el siguiente contenido a mostrar
var path = "/";
$.ajax({
type: 'POST',
dataType :'html',
url: path,
success: function(data) {
alert(data);
$('#cuerpo-tabla').append(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("error"); // always jump here!! that's the problem!
}
});
}
});
and Routing.yml index:
path: /
defaults: { _controller: UsuarioBundle:Default:index }