douyong6585 2015-09-14 20:17
浏览 45

一个简单的请求Ajax jquery symfony 2

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 }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 平滑拟合曲线该如何生成
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集