diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/www/js/gftranslate.js | 5 | ||||
| -rw-r--r-- | src/www/js/support.js | 25 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/www/js/gftranslate.js b/src/www/js/gftranslate.js index cf85a28e3..c0a47cfb3 100644 --- a/src/www/js/gftranslate.js +++ b/src/www/js/gftranslate.js @@ -7,7 +7,10 @@ gftranslate.jsonurl="/robust/Translate8.pgf" gftranslate.grammar="Translate" // the name of the grammar gftranslate.call=function(querystring,cont) { - http_get_json(gftranslate.jsonurl+querystring,cont) + function errcont(text,code) { + cont([{translations:[{error:code+" "+text}]}]) + } + http_get_json(gftranslate.jsonurl+querystring,cont,errcont) } // Translate a sentence diff --git a/src/www/js/support.js b/src/www/js/support.js index 934ea0f96..2c7dd782e 100644 --- a/src/www/js/support.js +++ b/src/www/js/support.js @@ -125,15 +125,32 @@ function ajax_http_post(url,formdata,callback,errorcallback) { // JSON via AJAX function ajax_http_get_json(url,cont,errorcallback) { - ajax_http_get(url, with_json(cont), errorcallback); + ajax_http_get(url, with_json(cont,errorcallback), errorcallback); } function ajax_http_post_json(url,formdata,cont,errorcallback) { - ajax_http_post(url, formdata, with_json(cont), errorcallback); + ajax_http_post(url, formdata, with_json(cont,errorcallback), errorcallback); +} + +function with_json(cont,errorcallback) { + return function(txt){ + if(txt) { + try { + var json=eval("("+txt+")") + } catch (e) { + if(errorcallback) + errorcallback("JSON parsing problem",500,"text/plain") + return + } + cont(json); + } + else { + if(errorcallback) + errorcallback("Empty response form server (crash?)",500,"text/plain") + } + } } -function with_json(cont) { return function(txt){cont(eval("("+txt+")"));} } - function sameOrigin(url) { var a=empty("a"); a.href=url; // converts to an absolute URL |
