我有一个 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);
});
});
});