comparison lib/js/urweb.js @ 1763:22858505bb2d

Allow RPC and run it synchronously in onunload event.
author Vladimir Shabanov <vshabanoff@gmail.com>
date Wed, 16 May 2012 22:46:35 +0400
parents e9587120831a
children 25824a0e8bf1
comparison
equal deleted inserted replaced
1762:a6eab6820b37 1763:22858505bb2d
1182 var sig = null; 1182 var sig = null;
1183 1183
1184 var unloading = false, inFlight = null; 1184 var unloading = false, inFlight = null;
1185 1185
1186 function unload() { 1186 function unload() {
1187 unloading = true;
1188
1189 for (; inFlight; inFlight = inFlight.next) { 1187 for (; inFlight; inFlight = inFlight.next) {
1190 inFlight.data.abort(); 1188 inFlight.data.abort();
1191 } 1189 }
1192 } 1190 }
1193 1191
1194 function requestUri(xhr, uri, needsSig, isRpc) { 1192 function requestUri(xhr, uri, needsSig, isRpc) {
1195 if (unloading)
1196 return;
1197
1198 var extraData = null; 1193 var extraData = null;
1199 1194
1200 if (isRpc && uri.length > 2000) { 1195 if (isRpc && uri.length > 2000) {
1201 extraData = uri.substring(2000); 1196 extraData = uri.substring(2000);
1202 uri = uri.substring(0, 2000); 1197 uri = uri.substring(0, 2000);
1203 } 1198 }
1204 1199
1205 xhr.open("POST", uri, true); 1200 xhr.open("POST", uri, !unloading);
1206 xhr.setRequestHeader("Content-type", "text/plain"); 1201 xhr.setRequestHeader("Content-type", "text/plain");
1207 try { 1202 try {
1208 xhr.setRequestHeader("Content-length", "0"); 1203 xhr.setRequestHeader("Content-length", "0");
1209 xhr.setRequestHeader("Connection", "close"); 1204 xhr.setRequestHeader("Connection", "close");
1210 } catch (e) { } 1205 } catch (e) { }