Stephan-v
Stephan-v

Reputation: 20297

Sending dynamic id and base url to laravel route in Jquery

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);
    });
  });  
});

Upvotes: 0

Views: 3054

Answers (1)

Teshte
Teshte

Reputation: 632

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)

Upvotes: 1

Related Questions