This example demonstrates how a cookie can be set through a JQuery Ajax request to the HTTP server.|
Operate as follow;
- Enter a new cookie value and press button "create cookie".
CGI program JQRACOOKIE receives the Ajax request and returns an invisible section that creates that cookie.
Cookie information is removed from the web page.
- Press the button "display cookie".
CGI program JQRACOOKIE receives the Ajax request, retrieves the cookie and returns a section that updates
the page character string containing the cookie value.
Note 1 - Ajax responses from CGI programs must always provide an appropriate HTTP header.
Without an HTTP header the internet browser cannot understand the type of the incoming script,
and quits with HTTP error 500.
In this example,
Content-type: text/html ...
in the second Ajax call, the returned string starts with the HTTP header Content-type: text/plain ...
Note 2 - In order to notify possible HHTTP errors, in this example both the Ajax calls feature a call-back parameter
to check return errors.
- In the first Ajax call, the returned string starts with the HTTP header
For more info about Ajax "load" call-back procedures,
see this page.