0

I want define url like this:

var id = $('#id').val();
    
url: "category/(my defined id variable here)/edit"

How can I do something like this?

I am creating project using Laravel 5.4.

Here I use resource controller that why I need this kind of URL to get my controller function.

This is the script part where I use ajax to insert data to database:

<script>
            $(document).ready(function(){
               $(document).on('click','#edit',function(){
                   $('#modelTile').text('Edit Category');
                   $('#addItem').val($(this).data('name'));
                   $('#id').val($(this).data('id'));
                   $('#yesdelete').hide();
               });
               $('.modal-footer').on('click','#saveChange',function(){
                   
                  var name = $('#addItem').val();
                   var id = $('#id').val();
                   var token ='{{csrf_field()}}';
                   $.ajax({
                       method : 'post',
                       url : "category/{'id'}/edit",
                   });
                   conlose.log (url);
               });
                
            });
        </script>

1 Answer 1

1

Replace your code to

$.ajax({
    method : 'post',
    url : "category/"+id+"/edit",
});
Sign up to request clarification or add additional context in comments.

1 Comment

I am highly grateful to you. :) Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.