php - 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?

This is the route url I'm working with.

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



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)

People are also looking for solutions to the problem: php - Capturing repeating sub pattern


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.