From 2b09e70b4ac759a72cb4cb68b615f5380978f08f Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 21 Jul 2020 13:19:19 +0200 Subject: allow specifying content-type in ajax_http --- src/www/js/support.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/www') diff --git a/src/www/js/support.js b/src/www/js/support.js index 2c7dd782e..fd84532c7 100644 --- a/src/www/js/support.js +++ b/src/www/js/support.js @@ -89,7 +89,7 @@ function GetXmlHttpObject(handler) return objXMLHttp } -function ajax_http(method,url,body,callback,errorcallback) { +function ajax_http(method,url,body,contenttype,callback,errorcallback) { var http=GetXmlHttpObject() if (!http) { var errortext="Browser does not support HTTP Request"; @@ -109,17 +109,20 @@ function ajax_http(method,url,body,callback,errorcallback) { } http.onreadystatechange=statechange; http.open(method,url,true) + if (contenttype != null) { + http.setRequestHeader("Content-Type", contenttype) + } http.send(body) } return http } function ajax_http_get(url,callback,errorcallback) { - ajax_http("GET",url,null,callback,errorcallback) + ajax_http("GET",url,null,null,callback,errorcallback) } function ajax_http_post(url,formdata,callback,errorcallback) { - ajax_http("POST",url,formdata,callback,errorcallback) + ajax_http("POST",url,formdata,null,callback,errorcallback) // See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects } -- cgit v1.2.3 From 8bc4cc71878cdf9d281678f3c0ca9e7ee7d49e28 Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 21 Jul 2020 22:29:00 +0200 Subject: added function for posting query strings. scales better than get. --- src/www/js/support.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/www') diff --git a/src/www/js/support.js b/src/www/js/support.js index fd84532c7..e999f8298 100644 --- a/src/www/js/support.js +++ b/src/www/js/support.js @@ -135,6 +135,10 @@ function ajax_http_post_json(url,formdata,cont,errorcallback) { ajax_http_post(url, formdata, with_json(cont,errorcallback), errorcallback); } +function ajax_http_post_querystring_json(url,querystring,cont,errorcallback) { + ajax_http("POST",url,querystring,"application/x-www-form-urlencoded",with_json(cont,errorcallback),errorcallback); +} + function with_json(cont,errorcallback) { return function(txt){ if(txt) { -- cgit v1.2.3