Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajax data and image upload laravel

<form name="data-form" id="data-form" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="file" name="img_thumbnail" class="form-control">
</form>
<script type="text/javascript">
    $(function () {
        $.ajaxSetup({
        headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
        });
       $('body').on('click', '#saveBtn', function(){
            var url;
            var registerForm = $("#data-form");
            var formData = registerForm.serialize();
            $(this).html('saving...');
            $('#saveBtn').attr('disabled',true);

            $.ajax({
                enctype: 'multipart/form-data',
                url: '{{ route('blog.store') }}',
                type:'POST',
                data:formData,
                success:function(data) {
                    console.log(data);
                    if(data.errors) {
                   }
                    if(data.success) {
                    }
                    $('#saveBtn').html('Save Data');
                    $('#saveBtn').attr('disabled',false);
                },
                error: function (data) {
                  console.log('Error:', data);
                  $('#saveBtn').html('Save Data');
              }

            });
        });
 });
    </script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: react map key increment 
Javascript :: jquery copy all options from select to another 
Javascript :: onclick add class javascript 
Javascript :: next js active nav link 
Javascript :: jquery setinterval clear after first attempt 
Javascript :: angular declare variable in a file 
Javascript :: How to know react and react-native version 
Javascript :: click button when press enter javascript 
Javascript :: hide cursor p5js 
Javascript :: How to save input from box html 
Javascript :: 413 payload too large nodejs 
Javascript :: return longest string from array 
Javascript :: charcodeat vs codepointat 
Javascript :: get timezone javascript 
Javascript :: javascript iterate object 
Javascript :: window location redirect javascript 
Javascript :: click listener on by class name in javascript 
Javascript :: sort array of objects javascript 
Javascript :: hover jquery 
Javascript :: console redux state shows proxy 
Javascript :: Error: [ProtectedRoute] is not a <Route component 
Javascript :: Express’s default X-Powered-By header Disabling 
Javascript :: nodejs execute every minute 
Javascript :: knockout dump variable 
Javascript :: angular json pipe pretty 
Javascript :: component did mount in hooks 
Javascript :: Vanilla JS (on)load with page 
Javascript :: append sibling javascript after first child 
Javascript :: javascript print object pretty 
Javascript :: js replace characters in a string 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =