Page 1 of 1

Error loading jQuery from SPIFFS / AsyncWebServer

Posted: Sun Apr 26, 2020 3:16 pm
by Munque
Error loading jQuery from SPIFFS / AsyncWebServer

I'm testing jQuery on ESP32, calling it from SPIFFS using AsyncWebServer.

Using JQ Version https://code.jquery.com/jquery-3.5.0.min.js causes an error in the browser when it tries to load:
SyntaxError: Unexpected identifier 'Test'. Expected a ';' following a return statement. (On Line 2)

I get the same error running the uncompressed version (https://code.jquery.com/jquery-3.5.0.js) on line 226 which shows the culprit as
"return ( i + 1 ) % 2;" in the file
"return ( i + 1 ) Test 2;" in the browser inspector

I've got the same jQuery file running in a number of other applications so I'm assuming it's not a problem with the jQuery itself.
Perhaps something about the way the AsyncWebServer or SPIFFS delivers the contents -- an encoding or text character perhaps
Thinking about this line, in particular: request->send(SPIFFS, "/Jq.js", String(), false, processor);

Here's the .ino file

Code: Select all

#include <WiFi.h>
#include "ESPAsyncWebServer.h"
#include "SPIFFS.h"
const char* Ssid = "ESP32-Access-Point";
const char* Pwd = "123456789";
AsyncWebServer EspServer(80);

void setup() {
	Serial.begin(115200);
	Serial.print("Setting AP (Access Point)…");
	if(!SPIFFS.begin(true)){
		Serial.println("An Error has occurred while mounting SPIFFS");
		return;
	}
	WiFi.softAP(Ssid, Pwd);
	Serial.print("AP IP address: ");
	Serial.println(WiFi.softAPIP());
	EspServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
		request->send(SPIFFS, "/index.html", String(), false, processor);
	});
	EspServer.on("/Js.js", HTTP_GET, [](AsyncWebServerRequest *request){
		request->send(SPIFFS, "/Js.js", String(), false, processor);
	});
	EspServer.on("/Jq.js", HTTP_GET, [](AsyncWebServerRequest *request){
		request->send(SPIFFS, "/Jq.js", String(), false, processor);
	});
	
	EspServer.begin();
}

void loop(){

}

String processor(const String& var){
	Serial.println(var);
	return "Test";
}

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Posted: Sun Apr 26, 2020 3:25 pm
by Munque
Partially answering my own question here: It's apparently something to do with the "processor" function, returning "Test"
Not yet sure what that function does in the scheme of things.

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Posted: Sun Apr 26, 2020 3:39 pm
by boarchuz
% is used to identify placeholders in AsyncWebServer so it will become a mess if there are other % characters in the file.

Define something else for TEMPLATE_PLACEHOLDER (eg. `).

See https://github.com/me-no-dev/ESPAsyncWe ... Impl.h#L62

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Posted: Sun Apr 26, 2020 3:49 pm
by Munque
boarchuz wrote:
Sun Apr 26, 2020 3:39 pm
% is used to identify placeholders in AsyncWebServer so it will become a mess if there are other % characters in the file.

Define something else for TEMPLATE_PLACEHOLDER (eg. `).

See https://github.com/me-no-dev/ESPAsyncWe ... Impl.h#L62
I ended up removing 'processor' from the request->send(SPIFFS, "/Jq.js", String(), false, processor); and all is well.
But now knowing how it works / what it's there for -- that'll come in handy at some point.
Thanks for you help!