comparison src/site.js @ 4:8896ffd7b152

start login
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 22 Oct 2023 23:53:59 -0600
parents
children 88f425d261b3
comparison
equal deleted inserted replaced
3:43814e9f5802 4:8896ffd7b152
1 'use strict';
2
3 function ajax(url,postData,context) {
4 let request = new XMLHttpRequest();
5 let method = postData ? 'POST' : 'GET';
6 request.open( method, url );
7 if( postData )
8 request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
9 request.onload = function() {
10 if( request.status !== 200 ) {
11 console.log( 'ajax failed: ' + request.status );
12 if( request.responseText )
13 document.write('<pre>'+request.responseText+'</pre>');
14 return;
15 }
16 try {
17 eval( request.responseText );
18 } catch(e) {
19 console.log( request.responseText );
20 window.err = '\najax-url = ' + url;
21 throw e;
22 }
23 };
24 request.send(postData);
25 }
26
27 window.onerror = function(msg, url, line, col, error) {
28 if (!url)
29 return;
30 let err = msg;
31 err += '\nurl = ' + url;
32 if (url != window.location)
33 err += '\npage = ' + window.location;
34 err += '\nline = '+line;
35 if (col)
36 err += '\ncolumn = ' + col;
37 if (error && error.stack)
38 err += '\nstack = ' + error.stack;
39 if( window.err ) {
40 err += window.err;
41 window.err = null;
42 }
43 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
44 };
45
46 function logout() {
47 document.cookie = 'user=; Max-Age=0; path=/;';
48 location = '/';
49 }