Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Tue Jun 02 16:19:34 2020 +0000
Parent:
137:3b6632374855
Child:
139:e189c6669983
Commit message:
Modified AjaxRequest to AjaxSendNameValue in order to be able to encode '=' and '?' correctly

Changed in this revision

common/web-ajax-class.inc Show annotated file Show diff for this revision Revisions of this file
common/web-ajax-class.js Show annotated file Show diff for this revision Revisions of this file
web-add.c Show annotated file Show diff for this revision Revisions of this file
--- a/common/web-ajax-class.inc	Tue Jun 02 08:32:21 2020 +0000
+++ b/common/web-ajax-class.inc	Tue Jun 02 16:19:34 2020 +0000
@@ -83,27 +83,37 @@
 "        ajaxOverrideBlockUpdateOnFocus_ = false; //Received response so reset override after display\n"
 "   }\n"
 "}\n"
-"function ajaxSendAjaxRequest_(request) //Used by this script and from HTML page\n"
+"function ajaxSendNameValue_(name, value) //Used by this script and from HTML page\n"
 "{\n"
 "    ajaxXhr_ = new XMLHttpRequest();\n"
 "    ajaxXhr_.onreadystatechange = ajaxHandleAjaxResponse_;\n"
-"    if (request)\n"
+"    if (name)\n"
 "    {\n"
-"        request = request.split('%').join('%25');\n"
-"        request = request.split('+').join('%2B');\n"
-"        ajaxXhr_.open('GET', ajaxServer_ + '?' + request, true);\n"
+"        if (value)\n"
+"        {\n"
+"            value = value.split('%').join('%25'); //Encode '%'s first\n"
+"            value = value.split('+').join('%2B');\n"
+"            value = value.split('=').join('%3D');\n"
+"            value = value.split('?').join('%3F');\n"
+"            value = value.split('#').join('%23');\n"
+"            ajaxXhr_.open('GET', ajaxServer_ + '?' + name + '=' + value, true);\n"
+"        }\n"
+"        else\n"
+"        {\n"
+"            ajaxXhr_.open('GET', ajaxServer_ + '?' + name, true);\n"
+"        }\n"
 "    }\n"
 "    else\n"
 "    {\n"
-"        ajaxXhr_.open('GET', ajaxServer_                , true);\n"
+"        ajaxXhr_.open('GET', ajaxServer_, true);\n"
 "    }\n"
 "    ajaxXhr_.send();\n"
 "    ajaxMsCountAtAjaxSend_ = ajaxMs_;\n"
 "}\n"
-"function AjaxRequest(request) //From html\n"
+"function AjaxSendNameValue(name, value) //From html\n"
 "{\n"
 "    ajaxOverrideBlockUpdateOnFocus_ = true; //Request has come from an update\n"
-"    ajaxSendAjaxRequest_(request);\n"
+"    ajaxSendNameValue_(name, value);\n"
 "}\n"
 "\n"
 "//Private functions\n"
--- a/common/web-ajax-class.js	Tue Jun 02 08:32:21 2020 +0000
+++ b/common/web-ajax-class.js	Tue Jun 02 16:19:34 2020 +0000
@@ -83,27 +83,37 @@
         ajaxOverrideBlockUpdateOnFocus_ = false; //Received response so reset override after display
    }
 }
-function ajaxSendAjaxRequest_(request) //Used by this script and from HTML page
+function ajaxSendNameValue_(name, value) //Used by this script and from HTML page
 {
     ajaxXhr_ = new XMLHttpRequest();
     ajaxXhr_.onreadystatechange = ajaxHandleAjaxResponse_;
-    if (request)
+    if (name)
     {
-        request = request.split('%').join('%25'); //Encode '%'s first
-        request = request.split('+').join('%2B');
-        ajaxXhr_.open('GET', ajaxServer_ + '?' + request, true);
+        if (value)
+        {
+            value = value.split('%').join('%25'); //Encode '%'s first
+            value = value.split('+').join('%2B');
+            value = value.split('=').join('%3D');
+            value = value.split('?').join('%3F');
+            value = value.split('#').join('%23');
+            ajaxXhr_.open('GET', ajaxServer_ + '?' + name + '=' + value, true);
+        }
+        else
+        {
+            ajaxXhr_.open('GET', ajaxServer_ + '?' + name, true);
+        }
     }
     else
     {
-        ajaxXhr_.open('GET', ajaxServer_                , true);
+        ajaxXhr_.open('GET', ajaxServer_, true);
     }
     ajaxXhr_.send();
     ajaxMsCountAtAjaxSend_ = ajaxMs_;
 }
-function AjaxRequest(request) //From html
+function AjaxSendNameValue(name, value) //From html
 {
     ajaxOverrideBlockUpdateOnFocus_ = true; //Request has come from an update
-    ajaxSendAjaxRequest_(request);
+    ajaxSendNameValue_(name, value);
 }
 
 //Private functions
--- a/web-add.c	Tue Jun 02 08:32:21 2020 +0000
+++ b/web-add.c	Tue Jun 02 16:19:34 2020 +0000
@@ -171,7 +171,7 @@
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
-    HttpAddF   ("  <div class='toggle' id='%s' tabindex='0' dir='ltr' onclick='AjaxRequest(\"%s=1\")' onkeydown='return event.keyCode != 13 || AjaxRequest(\"%s=1\")'>\r\n", id, name, name);
+    HttpAddF   ("  <div class='toggle' id='%s' tabindex='0' dir='ltr' onclick='AjaxSendNameValue(\"%s\", \"1\")' onkeydown='return event.keyCode != 13 || AjaxSendNameValue(\"%s\", \"1\")'>\r\n", id, name, name);
     HttpAddText("    <div class='slot'></div><div class='knob'></div>\r\n");
     HttpAddText("  </div>\r\n");
     HttpAddText("</div>\r\n");
@@ -187,14 +187,14 @@
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
-    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>\r\n", inputwidth, id, name);
+    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxSendNameValue(\"%s\", this.value)'>\r\n", inputwidth, id, name);
     HttpAddText("</div>\r\n");
 }
 void WebAddAjaxInputSuffix(const char* label, float inputwidth, const char* id, const char* name, const char* suffix)
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div>%s</div>\r\n", label);
-    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>%s\r\n", inputwidth, id, name, suffix);
+    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxSendNameValue(\"%s\", this.value)'>%s\r\n", inputwidth, id, name, suffix);
     HttpAddText("</div>\r\n");
 }
 void WebAddAjaxLabelled(const char* label, const char* id)
@@ -215,7 +215,7 @@
 {
     HttpAddText("<div class='line'>\r\n");
     HttpAddF   ("  <div id='%s'></div>\r\n", labelId);
-    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxRequest(\"%s=\" + this.value)'>\r\n", inputwidth, id, name);
+    HttpAddF   ("  <input type='text' style='width:%.1fem;' id='%s' onchange='AjaxSendNameValue(\"%s\", this.value)'>\r\n", inputwidth, id, name);
     HttpAddText("</div>\r\n");
 }