Skip to content

Instantly share code, notes, and snippets.

@sysnajar
Created November 20, 2015 22:16
Show Gist options
  • Select an option

  • Save sysnajar/181a21d88d8161592d76 to your computer and use it in GitHub Desktop.

Select an option

Save sysnajar/181a21d88d8161592d76 to your computer and use it in GitHub Desktop.
File upload snippet
<input type='file' id='fileUpload' style='display:none'> <---- 1. file input
<li style='display:inline'> <i class="clip-folder-upload" onclick='uploadAttachment(this);'></i> </li> <--- 2. icon trigger
<script src="assets/js/ajaxfileupload.js"></script> <--3. js file
function upload()
{
var id = 'file';
var val = $('#'+id).val();
if(val=='')return;
$('#uploadDiv').hide();
$('#uploadingDiv').show();
$.ajaxFileUpload
(
{
url:'upload/map_attr.htx',
secureuri:false,
fileElementId:id,
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
onUploadError(data.error);
}else
{
alert('success');
showUpload();
}
},
error: function (data, status, e)
{
onUploadError(e);
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment