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 :: prettier printWidth 
Javascript :: js detect object has key 
Javascript :: random key generator 
Javascript :: vue style background color 
Javascript :: get window size on resizing 
Javascript :: flatten nested object 
Javascript :: trigger click on first row datatable jquery 
Javascript :: js string to arraybuffer 
Javascript :: substr method 
Javascript :: create global variable inside function JavaScript 
Javascript :: jest express testing 
Javascript :: js run command in terminal 
Javascript :: connect to existing collection mongoose 
Javascript :: axios post request progress 
Javascript :: bind jquery 
Javascript :: url to buffer node.js 
Javascript :: javascript find factorial 
Javascript :: javascript how to do if else 
Javascript :: shuffle array in javascript 
Javascript :: date range npm 
Javascript :: javascript minute and second to convert seconds 
Javascript :: route guard in react js 
Javascript :: next js get gurrent page params 
Javascript :: how to make a discord bot send a message 
Javascript :: nodejs mysql query 
Javascript :: download file in react 
Javascript :: best javascript books 
Javascript :: react native add bottom tab and drawer menu 
Javascript :: @output() angular 
Javascript :: javascript Assigning to a non-writable property is not allowe 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =