File uploading using Ajax

var file_data;
var upload_size;
var file_size;
var file_last_modified;
var formdata = new FormData();
$(“#file”).change(function(){
if(this.files[0].size < 10000)
{
upload_size = “ok”;
file_size = this.files[0].size;
file_last_modified = this.files[0].lastModified;
file_data = this.files[0];
formdata.append(“images”,file_data,file_data.name);
alert(file);
}else{
upload_size = “not ok”;
}

var filetype = $(“#file”).val().split(“.”);
$.ajax({
type:’POST’,
data:formdata,
processData: false,
contentType: false,
url:’site url’,
beforeSend:function(xhr){
xhr.setRequestHeader(“requestType”, “vendorPhotoAdmin”);
xhr.setRequestHeader(“fileType”, filetype[1]);
xhr.setRequestHeader(“fileSize”, file_size);
xhr.setRequestHeader(“lastModified”, file_last_modified);
xhr.setRequestHeader(“sessionId”, key[1]);
xhr.setRequestHeader(“vendorId”, vendor_key[0]);
xhr.setRequestHeader(“fileName”, $(“#file”).val());
alert($(“#file”).val());
},
success:function(data){
alert(data);
}
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s