Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // events.js
- const onSubmitUploadGif = (handler) => {
- $(document).on('submit', '.upload-gif', handler);
- };
- // handlers.js
- const handleSubmitUploadGif = async (event) => {
- event.preventDefault();
- try {
- const formData = new FormData();
- const f = $('#gif-file')[0].files[0];
- formData.append('file', f);
- await uploadGif(formData);
- } catch (error) {
- console.error(error);
- }
- };
- // remote.js
- const uploadGif = async (data) => {
- const response = await fetch(uploadUrl, {
- method: 'POST',
- body: data
- });
- const result = await response.json();
- return result;
- };
Advertisement
Add Comment
Please, Sign In to add comment