0

I have a jquery ajax function that updates a rating that is set for a contest and sends that to a controller to change the database var.

But how do I dynamically get the contest id and base url of the website from the url into my jquery function?

http://ontwerpwedstrijden.dev/contests/1

This is the route url I'm working with.

$(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);
    });
  });  
});
Stephan-v
  • 19,255
  • 31
  • 115
  • 201

1 Answers1

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)

Community
  • 1
  • 1
Teshte
  • 624
  • 1
  • 7
  • 26