image upload jquery code example

Example 1: Upload image via ajax (jquery)

var form = new FormData();
form.append('varName','data');
$.ajax({
  type:'POST',
  url: $(this).attr('action'),
  data:formData,
  cache:false,
  contentType: false,
  processData: false,
  success:function(data){
    //function here
  },
  error: function(data){
    //function here
  }
});

Example 2: jquery preload images

//preloading Images with jQuery
function preloadImages(images) {
    $(images).each(function(){
        $('<img/>')[0].src = this;
    });
}

preloadImages([
    'images/image1.png',
    'images/image2.png'
]);