skip to Main Content

I have a modal where a user fill the data and when user press the submit button, a id fetch from jQuery and save data in datable according to the user id.
So, I have to fetch the id from jQuery and have to pass through PHP variable.

Here is my query for changing my form URL:

$('#get_form').attr('action', '{{ url("admin/report/update/"."$id="obj.data('id'))" }}');

And, here is my form

<form action="" id = "get_form" method="post" class="ajax-form modal-content" enctype="multipart/form-data">

I am unable to set the URL perfectly.

2

Answers


  1. You’re mixing blade with js. Try formatting the url like this:

    const url = "{{ url('admin/report/update/:id') }}".replace(':id', obj.data('id'))
    // generates admin/report/update/1 assuming obj.data('id') is equal to 1
    
    $('#get_form').attr('action', url);
    
    Login or Signup to reply.
  2.  var id = $('some-id').val();  // a hidden value
    
     var url = "{{ url('admin/report/update/') }}" + id;
    
     $('#get_form').attr('action', url);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search