Mercurial Hosting > freedit
comparison src/site.js @ 7:0472897e790d
add javascript
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 23 Jun 2022 23:38:03 -0600 |
parents | |
children | 94e26bffd4fb |
comparison
equal
deleted
inserted
replaced
6:9166f6a14021 | 7:0472897e790d |
---|---|
1 | |
2 function ajax(url,postData) { | |
3 let request = new XMLHttpRequest(); | |
4 let method = postData ? 'POST' : 'GET'; | |
5 request.open( method, url ); | |
6 if( postData ) | |
7 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' ); | |
8 request.onload = function() { | |
9 if( request.status !== 200 ) { | |
10 window.console && console.log( 'ajax failed: ' + request.status ); | |
11 if( request.responseText ) | |
12 document.write('<pre>'+request.responseText+'</pre>'); | |
13 return; | |
14 } | |
15 eval( request.responseText ); | |
16 }; | |
17 request.send(postData); | |
18 } | |
19 | |
20 window.onerror = function(msg, url, line, col, error) { | |
21 if (!url) | |
22 return; | |
23 let err = msg; | |
24 err += '\nurl = ' + url; | |
25 if (url != window.location) | |
26 err += '\npage = ' + window.location; | |
27 err += '\nline = '+line; | |
28 if (col) | |
29 err += '\ncolumn = ' + col; | |
30 if (error && error.stack) | |
31 err += '\nstack = ' + error.stack; | |
32 ajax( '/error_log.js', 'err='+encodeURIComponent(err) ); | |
33 }; |