|
From: | Noam Weissman |
Subject: | Re: [lwip-users] httpd: how to implement AJAX |
Date: | Tue, 14 Nov 2017 12:51:04 +0000 |
Hi, Yes I use a different server. My server code was based on a variation of the httpd code + many additions. I use POST to send the user+password and no it is not encoded… this is mainly for simple use. The SSID is not a cookie… The SSID’s are handles in a separate task that does the house keeping. Regarding the single file trick you may be right but this is how it works for me and I OK with it
J Regarding the GET/POST params… as the server parses the URL it also parses the GET params. BR, Noam. From: lwip-users [mailto:lwip-users-bounces+address@hidden
On Behalf Of Giuseppe Modugno Il 13/11/2017 18:04, Noam Weissman ha scritto: Yes SSID is a session ID that had been added to my own server code.
So are you using a completely different HTTP server from the httpd that is in apps folder of lwip main source? When a user askes for a page and there is no ssid the server will redirect (send a 303)
And load a login page instead. After the user writes user+password the data is sent to The server.
How do you send user+password to the server? PUT? Do you encode these sensible values? The server call’s external code to check for validity of user+pass… if OK it
Request a new ssid from a separate task.
After that the web server sends the previously request page + ssid… every operation
at the browser side must add that ssid value.
Is it a cookie, right? Every time the web server gets a request
with the correct ssid it clears the related timeout. If the ssid timeouts and the user asks for some data it will again redirect to the login page. Do you call a specific function from main at regular intervals to clear all SSID that expire? Regarding AJAX: How do you handle SSI ?... I am doing it differently ? I have something like this in my code: const SSI_t SSI_Table[] =
{ {"mem_rout", mem_routing}, {"IOSel", IO_Selection}, {"get_users", get_users}, {"ajax_reply", AjaxReply}, {NULL, NULL} // last tag must always be NULL to close the list }; mem_routing, IO_Selection, get_users, and AjaxReply are call-back function that are called by the web server as a result of encountering the proper tag… for mem_routing it is <!--#mem_rout-->
I think LWIP_HTTPD_CUSTOM_FILES is simpler to use when you have a file that is completely dynamic. Your "single tag trick" works, but IMHO is too complex for what you have to do. my AjaxReply parses the GET params and after that does something like that: How AjaxReply() function could access GET params if they aren't accessible from the SSI handler? Most probably the answer is in the file state (LWIP_HTTPD_FILE_STATE) that is filled by httpd_cgi_handler() callback (as explained by goldsimon). // get action param Char *Action = ""> If(strcmp(Action, “do_something_1”) == 0) { }
elses If(strcmp(Action, “do_something_2”) == 0) { } else { // print a debug error : action unknown } Hope that helped, Noam. From: lwip-users [mailto:lwip-users-bounces+address@hidden]
On Behalf Of Giuseppe Modugno Il 13/11/2017 14:34, Noam Weissman ha scritto: Hi, I am using the following technic for AJAX. Create an empty file named ajax.shtml or ajax.html and add it to your file list. Inside the file you only write one tag without anything else. For example <!--#AjaxCall--> Do not add CR or LF just the tag !!. Now when you issue an AJAX call the WEB server opens the file, reads it and send its data. Because the file has only the tag it will parse it, call your handler for that tag and send back To the browser just your data !! Ok, so you use SSI to create dynamic data. I tried with custom files, because *all the content* is dynamic (and not only some parts, defined by specific tags). If you use Juery it will look something like this... actually a function used as an event handler in my own code: function resetIO() { //Remove the dialog returnToPage(); $.ajax({ url: "ajax.shtml", dataType : "text", type : "GET", cache : false, data : ({ ssid: ssid, a: 'opReset', type: 2 }), error : function() { showMessage("Network Error: Sorry, there was a problem connecting to the server."); }, success : function(result) { window.location.href = ""> } }); } In the above data you have the a: variable, this is your AJAX action !. If I understood well, data is translated in query string, in your example: In your own SSI/CGI code you have a table with tags + callbacks... one of the callback function Is your AJAX handler. Inside it you create an if <> else layout and handle the different actions. The prototype for SSI callbacks is: typedef u16_t (*tSSIHandler)( I don't see any reference to query string parameters. So how to select the right action? The HTTP server will read your ajax.shtml file and because it has nothing BUT your tag it will only send back the dynamic data you process in your ajax handling function. As said before, it works if the dynamic content depends only from the name of the file (ajax.shtml in your example) and not from the action in the query string (a=opReset).
_______________________________________________ lwip-users mailing list address@hidden https://lists.nongnu.org/mailman/listinfo/lwip-users |
[Prev in Thread] | Current Thread | [Next in Thread] |