繁体   English   中英

将动态ID和基本URL发送到jQuery中的laravel路由

[英]Sending dynamic id and base url to laravel route in Jquery

我有一个jquery ajax函数,该函数可以更新为比赛设置的评级,并将其发送到控制器以更改数据库var。

但是,如何从URL动态获取网站的竞赛ID和基本URL到我的jquery函数中呢?

http://ontwerpwedstrijden.dev/contests/1

这是我正在使用的路线网址。

$(function() {
  $(".radio").on("click",function(e) {  
    // dynamic variables
    var base = 'http://ontwerpwedstrijden.dev';
    var id = 1; // needs to be changed to the current url id
    // Ajax call 
    $.post(base+'/contests/'+id,{ rating: this.value}, function(data) {
      console.log(data);
    });
  });  
});

看看: 用JavaScript获取当前URL?

这样,您就可以获取url,然后从中提取所需的内容(在本例中为id)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM