Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajax laravel get values from form

<script>
var form = $('#postAddProject');
var button = $('#project-button');
var name = $('#name');
var link = $('#link');
var image = $('#image');
var token = $('input[name=_token]');
var message = $('#message');

var name_error = $('#name-error');
var link_error = $('#link-error');
var image_error = $('#image-error');

button.click(function (event){

event.preventDefault();

var formData = new FormData();
formData.append('name', name.val());
formData.append('link', link.val());
formData.append('image', image[0].files[0]); 

$.ajax({
url: form.attr('action'),
method: 'post',
dataType: 'json',
contentType: false,
processData: false,

headers: {
    'X-CSRF-TOKEN': token.val()
},

data: formData,

error: function (data) {

    if (data.status === 422) {

         name_error.html(data.responseJSON.name);
         link_error.html(data.responseJSON.link);
         image_error.html(data.responseJSON.image);

    } else {

         alert('success');
    }
}
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: ternaire javascript 
Javascript :: removing duplicates from array javascript 
Javascript :: sort algorithm for array of objects in js 
Javascript :: jquery get padding top without px 
Javascript :: axios post request progress 
Javascript :: get string from textbox javascript 
Javascript :: date format in javascript 
Javascript :: back button event listener javascript 
Javascript :: url to buffer node.js 
Javascript :: cet time zone right now 
Javascript :: js editable table 
Javascript :: react receiving socket muitple times 
Javascript :: jquery get parameter from url 
Javascript :: how to reverse array in javascript 
Javascript :: momentum 
Javascript :: Basic Vue JS Setup script for Laravel App 
Javascript :: String operators in JavaScript 
Javascript :: java script hash 
Javascript :: aos animation 
Javascript :: exec in node js 
Javascript :: why we use mongoose 
Javascript :: d3 force simulation 
Javascript :: trash alternate outline icon not coming to right side react 
Javascript :: google sheets get ranges 
Javascript :: check file name in url 
Javascript :: Redirect user when JavaScript is disabled with noscript 
Javascript :: ready function jq 
Javascript :: js lambda 
Javascript :: mock createRef jest react functional component 
Javascript :: timeout 30000 milliseconds 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =