Server, handle page after HTTP_POST

Hi Guys

Working on my first application, using a ESP8266 running a web server.

I can handle the HTTP_POST and save my data form the form I have (index.htm), when I post it runs the saveJson and saves my json file, this function works well

server.on("/update", HTTP_POST, saveJson); server.serveStatic("/", SPIFFS, "/www/index.htm", NULL); server.serveStatic("/config.json", SPIFFS, "/config.json");

I can't see to figure out, or find the answer, once I have run saveJson I want it to go back to the index.htm page, I have tried the following

server.serveStatic("/update", SPIFFS, "/www/index.htm", NULL);

Any help would be great

Thanks in advance

Brian

I can't see to figure out, or find the answer, once I have run saveJson I want it to go back to the index.htm page, I have tried the following

I can't see where your code does that.

Any help would be great

Without seeing your code, that seems unlikely.

Hi Thanks for your reply

Below is the code

bool saveJson() {
  StaticJsonBuffer<400> jsonBuffer;
  JsonObject& json = jsonBuffer.createObject();

  JsonArray& apsettings = json.createNestedArray("apsettings");
  apsettings.add("DefaultSSID"); apsettings.add( server.arg("ssidchk") ); apsettings.add( server.arg("pnum") );  
  
 
  File configFile = SPIFFS.open("/config.json", "w");
  if (!configFile) {
    Serial.println("Failed to open config file for writing");
    return false;
  }

  json.printTo(configFile);
  Serial.println("Config saved");
  return true;
}

void setup() {
	Serial.println();
	Serial.println("** Configuring access point **");
  	Serial.print("AP SSID : ");  Serial.println(APssid);
	Serial.print("AP IP address: "); Serial.println(myIP);
 
  	server.on("/update", HTTP_POST, saveJson);
  	server.serveStatic("/", SPIFFS, "/www/index.htm", NULL);
  	server.serveStatic("/config.json", SPIFFS, "/config.json", NULL);
	server.begin();
 	Serial.println("HTTP server started")


}

void loop() {  
	server.handleClient();
}

This will serve the index.htm page when I go to 192.168.4, this HTML page has JavaScript on it that reads the json file " config.json ", this page runs without problems

server.serveStatic("/", SPIFFS, “/www/index.htm”, NULL);
server.serveStatic("/config.json", SPIFFS, “/config.json”, NULL);

On the index.htm there is a form with an update button that calls “/update” which in real terms calls https://192.168.4.1/update, this then triggers

server.on("/update", HTTP_POST, saveJson);

which runs the “saveJson” function. However what I then need it to do is re-load the index,htm page after it has run the saveJson function, I thought all I need to do was add

server.on("/update", HTTP_POST, saveJson);
 server.serveStatic("/", SPIFFS, "/www/index.htm", NULL);
>> ADDED  server.serveStatic("/update", SPIFFS, "/www/index.htm", NULL);
 server.serveStatic("/config.json", SPIFFS, "/config.json", NULL);

but that does not work.
So trying to work out how I load the index.htm page after I gave run saveJson

Thanks

Brian

but that does not work.

That is useless information. Something happens in the web browser. Feel free to tell us that actually happens - before and after pictures are goof.

Something happens on the Arduino. Serial output would be worth seeing.

I found the answer, well a solution to the problem

after i have run the function that i needed i then have to do a HTTP call to relocation to root which then loads the index.htm page

server.sendHeader("Location", "/", true); //Redirect to our html web page server.send(302, "text/html", "");

Thanks