Mercurial Hosting > freedit
view src/site.js @ 33:4fdc4ec0050b
upload with uploadcare
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 01 Aug 2022 22:50:16 -0600 |
parents | 33731231093a |
children | c8d47981c74f |
line wrap: on
line source
function ajax(url,postData) { let request = new XMLHttpRequest(); let method = postData ? 'POST' : 'GET'; request.open( method, url ); let isMultipart = postData instanceof File; if( postData && !isMultipart ) request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); request.onload = function() { if( request.status !== 200 ) { window.console && console.log( 'ajax failed: ' + request.status ); if( request.responseText ) document.write('<pre>'+request.responseText+'</pre>'); return; } eval( request.responseText ); }; if(isMultipart) { let formData = new FormData(); formData.append( 'file', postData ); request.send(formData); } else { request.send(postData); } } window.onerror = function(msg, url, line, col, error) { if (!url) return; let err = msg; err += '\nurl = ' + url; if (url != window.location) err += '\npage = ' + window.location; err += '\nline = '+line; if (col) err += '\ncolumn = ' + col; if (error && error.stack) err += '\nstack = ' + error.stack; ajax( '/error_log.js', 'err='+encodeURIComponent(err) ); };