我正在尝试计算网站的重定向次数,例如当用户单击指向该网站的链接时。我正在通过以下方法通过请求获取网址:
/**
* @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);
}});});
答案 0 :(得分: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>