return data from a web POST request
Posted: Sun Sep 17, 2017 12:08 pm
I want to return data and indicate that a POST request was successful, but I am not sure how this is done with Netburner software
In the web page I have the following ajax call:
In the Netburner I have redirected the POST function using
and then the code to respond to the POST is as follows:
This code sets the time OK but always response with 'error'.
How can I get the code to send back either OK or error, and can i send back data as well.
I don't think i have to put the HTTP code in the rxBuffer.
I would have thought that the return code would be the correct signal but I have tried 0 and 1 as return codes and both give 'error'.
any help would be appreciated.
Thanks
Lachlan
In the web page I have the following ajax call:
Code: Select all
$.ajax({type: "POST", url: 'TIMESET', async: false, data: t, timeout: 4000,
success: function(data){
alert("OK" + data);
},
error: function () {
alert("Error updating time");
}
});
Code: Select all
oldPostHandler = SetNewPostHandler( doPost ); // Redirect Web page POST handler
Code: Select all
int doPost( int sock, char *fname, char *pData, char *rxBuffer ){
time_t RawTime;
if (strcmp("/TIMESET",fname) == 0){
RawTime = atol(pData); // time from browser in seconds
set_time( RawTime ); // Update the time
sprintf(rxBuffer, "HTTP/1.1 200 OK\r\n[data]");
return 0;
}
else
{
sprintf(rxBuffer, "HTTP/1.1 400");
return 1;
}
}
How can I get the code to send back either OK or error, and can i send back data as well.
I don't think i have to put the HTTP code in the rxBuffer.
I would have thought that the return code would be the correct signal but I have tried 0 and 1 as return codes and both give 'error'.
any help would be appreciated.
Thanks
Lachlan