0

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

但是如何从 url 动态获取网站的比赛 id 和基本 url 到我的 jquery 函数中?

http://ontwerpwedstrijden.dev/contests/1

这是我正在使用的路由 url。

$(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);
    });
  });  
});
4

1 回答 1

1

Check this out : Get current URL in JavaScript?

That way you get the url, and then from it, you can extract what you need (in this case the id)

于 2013-04-29T12:45:43.787 回答