Error loading jQuery from SPIFFS / AsyncWebServer

Munque
Posts: 25
Joined: Mon Feb 10, 2020 11:38 pm

Error loading jQuery from SPIFFS / AsyncWebServer

Postby Munque » Sun Apr 26, 2020 3:16 pm

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";
}

Munque
Posts: 25
Joined: Mon Feb 10, 2020 11:38 pm

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Postby Munque » Sun Apr 26, 2020 3:25 pm

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.

boarchuz
Posts: 605
Joined: Tue Aug 21, 2018 5:28 am

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Postby boarchuz » 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

Munque
Posts: 25
Joined: Mon Feb 10, 2020 11:38 pm

Re: Error loading jQuery from SPIFFS / AsyncWebServer

Postby Munque » Sun Apr 26, 2020 3:49 pm

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!

Who is online

Users browsing this forum: Majestic-12 [Bot] and 93 guests