php - Sending dynamic id and base url to laravel route in Jquery

517

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

Answer

Solution:

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

Source

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.