summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vladimir Shabanov <vshabanoff@gmail.com>2012-05-16 22:46:35 +0400
committerGravatar Vladimir Shabanov <vshabanoff@gmail.com>2012-05-16 22:46:35 +0400
commit3ffa0c777818ec5f00ec0617fa08ccba83b9cfe2 (patch)
treefdb57377024b18a1f94fd7595d0cbbc43c2caf49
parentc748824e2f051bcb05eb4ece541a96d1b55714e6 (diff)
Allow RPC and run it synchronously in onunload event.
-rw-r--r--lib/js/urweb.js7
-rw-r--r--src/c/urweb.c4
2 files changed, 3 insertions, 8 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 85d10d4a..40d080b8 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1184,17 +1184,12 @@ var sig = null;
var unloading = false, inFlight = null;
function unload() {
- unloading = true;
-
for (; inFlight; inFlight = inFlight.next) {
inFlight.data.abort();
}
}
function requestUri(xhr, uri, needsSig, isRpc) {
- if (unloading)
- return;
-
var extraData = null;
if (isRpc && uri.length > 2000) {
@@ -1202,7 +1197,7 @@ function requestUri(xhr, uri, needsSig, isRpc) {
uri = uri.substring(0, 2000);
}
- xhr.open("POST", uri, true);
+ xhr.open("POST", uri, !unloading);
xhr.setRequestHeader("Content-type", "text/plain");
try {
xhr.setRequestHeader("Content-length", "0");
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 2e16743c..802a1620 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -1336,8 +1336,8 @@ uw_Basis_string uw_Basis_maybe_onunload(uw_context ctx, uw_Basis_string s) {
if (ctx->script_header[0] == 0)
return "";
else {
- char *r = uw_malloc(ctx, 22 + strlen(s));
- sprintf(r, " onunload='unload();%s'", s);
+ char *r = uw_malloc(ctx, 37 + strlen(s));
+ sprintf(r, " onunload='unloading=true;%s;unload()'", s);
return r;
}
}