0

I have this code. And i want to put id as dynamic value to parameter of route. But i can't get the value of id i get only text id

i try these code:

var id = $(this).data('studentid');
var br_id = "{{ route('dep', ['student_id' =>"+id+"])}}";


$.ajax({
            url: br_id,
            type: "GET",
            success: function (data) {
                $('.replace').html(data);
                //alert('hello')
            },
            error: function (jQXHR, textStatus, errorThrown) {
                console.log(jQXHR);
                console.log(textStatus);
                console.log(errorThrown);
            }
        }); //end Ajax

and i get the below result:

http://localhost/library/public/dep/+id+

i want to show the id from select that is dynamic data and i want to put it in this parameter of route.Any solution for these?

showdev
  • 28,454
  • 37
  • 55
  • 73
Rajes
  • 103
  • 3
  • 14
  • Are you using Laravel? – showdev Oct 26 '18 at 18:32
  • @showdev yes i use laravel – Rajes Oct 26 '18 at 18:33
  • 1
    Possible duplicate of [Laravel 4, Pass a variable to route in javascript](https://stackoverflow.com/questions/27634285/laravel-4-pass-a-variable-to-route-in-javascript) OR [Use js function variable in route](https://stackoverflow.com/questions/42042682/use-js-function-variable-in-route). – showdev Oct 26 '18 at 18:34
  • @Taplar so i can't use route name in jquery. only url? – Rajes Oct 26 '18 at 18:35
  • 1
    Look at the duplicates showdev linked. The issue here is that you are trying to use a variable defined on the client side, while the `{{}}` is being executed on the server side, before the client ever runs – Taplar Oct 26 '18 at 18:36
  • @showdev thank you very much – Rajes Oct 26 '18 at 18:39
  • @Taplar ok i got it thank you very much – Rajes Oct 26 '18 at 18:39
  • Np. Sorry it took that long to catch that. I'm not up on laravel syntax to know that parts were pre-processing. I was thoroughly confused, lol – Taplar Oct 26 '18 at 18:40
  • As a side note, make sure to tag things like this with the related languages/environments in the future, ;) – Taplar Oct 26 '18 at 18:41
  • @Taplar lolz :) – Rajes Oct 26 '18 at 18:41

0 Answers0