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 = document.location;
           }
         });
       }

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:

    GET ajax.shtml?ssid=<ssid>&a=opReset&type=2

Of course, <ssid> is the value of ssid Javascript variable.

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)(
   #if LWIP_HTTPD_SSI_RAW
                                 const char* ssi_tag_name,
   #else /* LWIP_HTTPD_SSI_RAW */
                                 int iIndex,
   #endif /* LWIP_HTTPD_SSI_RAW */
                                 char *pcInsert, int iInsertLen
   #if LWIP_HTTPD_SSI_MULTIPART
                                 , u16_t current_tag_part, u16_t
   *next_tag_part
   #endif /* LWIP_HTTPD_SSI_MULTIPART */
   #if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
                                 , void *connection_state
   #endif /* LWIP_HTTPD_FILE_STATE */
                                 );

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).

Where is my error?

Another question. I saw ssid in your javascript example. Is it related to a "session identifier"? If so, did you implement a session mechanism over httpd?
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to