dimanche 6 novembre 2016

Trying to pass js value in Route Parameter : Laravel 5

Below is my code in Laravel.

<script language="javascript">
    $(document).ready(function() {
        var $_token         =   "{!! csrf_token() !!}";

        var data = {
            "_token"        : $_token, 
        };
        $.ajax({
            url:            '',
            method:         "POST",
            async:          true,
            data:           JSON.stringify(data),
            contentType:    "application/json; charset=utf-8",
            success: function (result) {
                $.each(result.Data, function( key, ServiceArea ) {
                    var URL = '{!! route("ServiceAreaDetails", ["ID" => 1]); !!}';
                });
            }
        });
    });
</script>

What is the point in discussion?

Value = 1 in this code is static. Can we make it dynamic? var URL = '{!! route("ServiceAreaDetails", ["ID" => 1]); !!}';

What's the problem?

Route function is server side coding. Is there any way to pass js value inside loop to this server side function parameter?

Js value will be ServiceArea.ID



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire