Ajax:POST请求的空参数

问题描述 投票:0回答:1

我正在尝试计算网站的重定向,例如当用户点击引用该网站的链接时。我在我的方法中通过以下请求获取网址:

    /**
     * @Route("/redirections")
     * @Method({"GET", "POST"})
     */
    public function redirectingtoAction(Request $request) {
        $em = $this->getDoctrine()->getManager();
        $query ="UPDATE urlproduit SET redirection = redirection + 1 WHERE url ='".$request->get('ur')."';";
        $statement = $em->getConnection()->prepare($query);
        $statement->execute();
        return new Response($request->get('ur'));
    }

这是我的树枝:

    <div class="col-4 store-border-button ">
    <p data-url="{{url.url}}"  class="btn btn-primary wd-shop-btn pull-right flux"> See the offer </p> 
   </div>

这是我的ajax电话:

     $('.flux').click(function(){
            ur=$(this).data('url');
            console.log(url);
            $.ajax({
    type: "POST",
    url: "../redirections",
    data : { param: 'ur', value: ur },
    success: function(data){
        //window.location.href=data;
        console.log(data);
    }});});

当检查_profiler时,你的总是空的如下:empty url param

ajax symfony-3.3
1个回答
0
投票

解决方案是:

function hits(url){

    $.ajax({
    type: "POST",
    url: "../redirects",
    data : {  url: url},
    success: function(data){
        window.location.href=data;

    }
    });
         };

我修改了按钮代码:

 <a href="{{url.url}}" target="_blank" onclick="hits('{{url.url}}');return false;" class="btn btn-primary wd-shop-btn pull-right" id="flux">
See offer </a>
© www.soinside.com 2019 - 2024. All rights reserved.