Created
January 24, 2017 02:10
-
-
Save ngalluzzo/45e461e1fa50270073fd1174cc283a8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
//this assumes you have a file field in your form with id=image | |
//when this field is updated, run the function | |
$('#image').change(function(e){ | |
var file = this.files[0]; | |
var form = new FormData(); | |
form.append('files', file); | |
$.ajax({ | |
url : "https://api.knack.com/v1/applications/[YOUR APP ID]/assets/image/upload", | |
headers: {"x-knack-application-id":"YOUR APP ID", | |
"x-knack-rest-api-key": "YOUR API KEY"}, | |
type: "POST", | |
cache: false, | |
contentType: false, | |
processData: false, | |
data : form, | |
success: function(response){ | |
$('.result').html(response.html) | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment