Error loading jQuery from SPIFFS / AsyncWebServer
Posted: 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
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";
}