我无法从ajax jquery向Controller发送一个值

时间:2015-10-04 18:59:39

标签: jquery ajax

我无法向控制器发送值(输入)。我正在使用输入进行搜索自动完成。代码ajax jquery是:

 $("#search").keyup(function () {
       var that = this,
        value = $(this).val();

        if (value.length >= minlength ) {
            alert(value);


            $.ajax({
                type: "POST",
                url: "http://localhost/PeopleSymfony/web/app_dev.php/searching",
                data: 'value='+value,
                success: function(msg){

                    //we need to check if the value is the same
                    if($('#buscador ul').is(':visible')) {
                        $("#buscador ul").html(msg);
                    }else{
                    $("#buscador").append(msg);
                    }
                }
            });
        }
    });

和控制器我做了一个获取请求"值"它不起作用。

public function searchingAction(){

            if (!$request->isXmlHttpRequest()) {// isn't it an Ajax request?
                return $this->render(
                        'UsuarioBundle:Default:index.html.twig'

                );

            }else{

                $key= $request->request->get('value');

                $manejador = new Manejador();
                $busqueda=$manejador->SearchBox($key);
                $cadena1="<ul>";
                for($i1 = 0; $i1 <count($busqueda); $i1++){
                    $cadena1.="<li>".$busqueda[$i1]."</li>";
                }
                $cadena1=$cadena1."</ul>";

                return new Response($cadena1);
            }
        }

它不起作用。需要帮助

0 个答案:

没有答案