Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajax form picture upload

$("#changeProfilePicForm").submit(function (e) {
    e.preventDefault();
    var $form = $(this);
    $.ajax({
        url: $form.attr('action'),
        type: "POST",
        data:  new FormData($form[0]),
        contentType: false,
        cache: false,
        processData: false,
        success: function (data) {
            console.log(data);
        },
        error: function(data){
            console.log(data);
        }           
    });
}));
Comment

ajax upload image

$(document).ready(function (e) {
    $('#imageUploadForm').on('submit',(function(e) {
        e.preventDefault();
        var formData = new FormData(this);

        $.ajax({
            type:'POST',
            url: $(this).attr('action'),
            data:formData,
            cache:false,
            contentType: false,
            processData: false,
            success:function(data){
                console.log("success");
                console.log(data);
            },
            error: function(data){
                console.log("error");
                console.log(data);
            }
        });
    }));

    $("#ImageBrowse").on("change", function() {
        $("#imageUploadForm").submit();
    });
});
Comment

image upload using jquery ajax

var formData = new FormData();
formData.append('file', $('#myfile')[0].files[0]); // myFile is the input type="file" control

var _url = '@Url.Action("UploadFile", "MyController")';

$.ajax({
    url: _url,
    type: 'POST',
    data: formData,
    processData: false,  // tell jQuery not to process the data
    contentType: false,  // tell jQuery not to set contentType
    success: function (result) {
    },
    error: function (jqXHR) {
    },
    complete: function (jqXHR, status) {
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript element text 
Javascript :: merge array within an array 
Javascript :: hit click function only once on first click jquery 
Javascript :: calculate today date javascript 
Javascript :: stylelint default config 
Javascript :: next js material ui typescript 
Javascript :: foreach javascript 
Javascript :: jquery remove option from select 
Javascript :: jquery target partial id 
Javascript :: jqurey text contains selector 
Javascript :: math.factorial 
Javascript :: how to get specific word from the string javascript 
Javascript :: faker.js avatar 
Javascript :: react aws s3 npm 
Javascript :: return more than 1 value from function js 
Javascript :: jquery checkbox listener not working on programmatically change 
Javascript :: javascript vue.js right click 
Javascript :: get random entry from array javascript 
Javascript :: rror: btoa is not defined 
Javascript :: check if the document is ready js 
Javascript :: disable key enter react-hook-form 
Javascript :: class element in javascript 
Javascript :: extract value from array of objects javascript 
Javascript :: change theme in react-toastify 
Javascript :: add props to jsx element 
Javascript :: post message in iframe javascript 
Javascript :: how to launch several async functions in node js 
Javascript :: notice before reload js 
Javascript :: js number format 
Javascript :: Reverse numbers from an array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =