Wapp

Check-in [39368df9be]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add another ajax form example, this time using x-www-form-urlencoded content.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 39368df9bed5a7e485bc8a505ec4a2e9d7087a39ab61f730fa453923005f08da
User & Date: drh 2018-01-29 01:10:03.727
Context
2018-01-29
18:08
Add the wapp-debug-puts-env command for debugging. (check-in: 95eb5f5c75 user: drh tags: trunk)
01:10
Add another ajax form example, this time using x-www-form-urlencoded content. (check-in: 39368df9be user: drh tags: trunk)
00:45
Move the "env.tcl" example script into the examples/ folder. (check-in: afbbaffbe0 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Added examples/formajax02.tcl.


























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This script demonstrates how to send form data as JSON using
# XMLHttpRequest
#
package require wapp
proc wapp-default {} {
  wapp-trim {
    <h1>Example Of Sending application/x-www-form-urlencoded Using AJAX</h1>
    <form id="nameForm">
    <table border="0">
    <tr><td align="right"><label for="firstName">First name:</label>&nbsp;</td>
        <td><input type="text" id="firstName" width="20">
    <tr><td align="right"><label for="lastName">Last name:</label>&nbsp;</td>
        <td><input type="text" id="lastName" width="20">
    <tr><td align="right"><label for="age">Age:</label>&nbsp;</td>
        <td><input type="text" id="age" width="6">
    <tr><td><td><input type="submit" value="Send">
    </table>
    </form>
    <script>
    document.getElementById("nameForm").onsubmit = function(){
      function val(id){ return escape(document.getElementById(id).value) }
      var jx = "firstname="+val("firstName")+
               "&lastname="+val("lastName")+
               "&age="+val("age");
      var xhttp = new XMLHttpRequest();
      xhttp.open("POST", "%string([wapp-param BASE_URL])/acceptjson", true);
      xhttp.setRequestHeader("Content-Type",
                             "application/x-www-form-urlencoded");
      xhttp.send(jx);
      return false
    }
    </script>
  }
}
proc wapp-page-acceptjson {} {
  global wapp
  puts "Accept Callback"
  puts "mimetype: [list [wapp-param CONTENT_TYPE]]"
  puts "content: [list [wapp-param CONTENT]]"
  foreach var [lsort [dict keys $wapp]] {
    if {![regexp {^[a-z]} $var]} continue
    puts "$var = [list [wapp-param $var]]"
  }
}
wapp-start $argv