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 consecutive numbers in array 
Javascript :: iterate over array of objects javascript 
Javascript :: float to euro curency 
Javascript :: jsonarray add jsonobject 
Javascript :: import modules js html 
Javascript :: object deep copy 
Javascript :: jquery set hidden field value 
Javascript :: iterate through array js 
Javascript :: react aos animation 
Javascript :: react proxy 
Javascript :: extract all link with javascript 
Javascript :: countdown in react js 
Javascript :: json data sample 
Javascript :: express get query parameters 
Javascript :: send serialized form data jquery 
Javascript :: add text to string javascript 
Javascript :: replace all js 
Javascript :: remove duplicated from array of ojects 
Javascript :: sequelize relation does not exist 
Javascript :: javascript set property for each object in array of objects 
Javascript :: fix footer 
Javascript :: javascript override shortcut 
Javascript :: react password hashing 
Javascript :: javascript urlsearchparams to string 
Javascript :: java script remove last character from string 
Javascript :: javascript print 
Javascript :: forjs check if key in json 
Javascript :: @tippyjs/react 
Javascript :: javascript storage get set item 
Javascript :: bootstrap dropdown doesnt work with angular 12 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =