Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 162 lines (120 sloc) 5.941 kB
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
1
2 <erl>
3
4
5 box(Str) ->
6 {'div',[{class,"box"}],
7 {pre,[], yaws_api:htmlize(Str)}}.
8
9 tbox(T) ->
10 box(lists:flatten(io_lib:format("~p",[T]))).
11
12
13 ssi(File) ->
14 {'div',[{class,"box"}],
15 {pre,[],
16 {ssi, File,[],[]}}}.
17
18 ss(A, File) ->
19 {ok, B} = file:read_file(
0be3c7e @klacke untabified all of yaws
authored
20 filename:join([A#arg.docroot, File])),
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
21 box(binary_to_list(B)).
22
23
24
25 out(A) ->
26 [{ssi, "TAB.inc", "%%",[{"json_intro", "choosen"}]},
27 {ehtml,
28 {'div', [{id, "entry"}],
29
30 [{h1, [], "AJAX through JSON RPC"},
31
0be3c7e @klacke untabified all of yaws
authored
32 {p, [],
33 {i, [],
34 ["Note: this documentation used to refer to the module "
35 "'yaws_jsonrpc'. This module has been depracated in favor "
36 "of 'yaws_rpc', which handles both JSON RPC, haXe and SOAP "
37 "remoting. All references to 'yaws_jsonrpc' on this page "
38 "were therefore changed to 'yaws_rpc'. For more specific "
39 "information about SOAP, refer to ",
40 {a, [{href, "/soap_intro.yaws"}], "the SOAP page."}]}},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
41 {p, [],
0be3c7e @klacke untabified all of yaws
authored
42 ["The Yaws Json binding is a way to have Javascript code in the "
43 "browser evaluate a remote procedure call in the Yaws server."
44 "JSON itself as described at ",
45 {a, [{href, "http://www.json.org/"}], "http://www.json.org/ "},
46 "is basically a simple marshaling format which can be used "
47 " from a variety of different programming languages, in particular "
48 " it completely straightforward to implement in Javascript."]},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
49 {p, [],
0be3c7e @klacke untabified all of yaws
authored
50 "The yaws JSON implementation consist of Javascript client and a "
51 " server side library which must be explicitly invoked by Erlang "
52 "code in a .yaws page."},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
53
54 {p,[],
0be3c7e @klacke untabified all of yaws
authored
55 "It is not particularly easy to show and explain an AJAX setup "
56 "through JSON RPC, but here is an attempt:"
57 },
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
58 {p,[],
0be3c7e @klacke untabified all of yaws
authored
59 "First we have an HTML page which:"},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
60 {ol, [],
0be3c7e @klacke untabified all of yaws
authored
61 [
62 {li,[],{p,[], "Includes the client side of the JSON library."
63 " The library is included in the yaws distribution "
64 " and it is found under \"www/jsolait/jsolait.js\" ."}},
65 {li,[],{p,[],"Second the HTML code defines the name of a method, "
66 "i.e. the name of a server side function which shall be "
67 " called by the client side Javascript code"}},
68 {li,[],{p,[],"Finally the HTML code defines a FORM which is "
69 "used to invoke the RPC. This is just a really simple "
70 "example, really any Javascript code can invoke any RPC in "
71 "more interesting scenarios than submitting a form"}}]},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
72
73 {p, [], "The HTML code looks like "},
74 ss(A,"json_sample.html"),
75 {p, [], ["This HTML code resides in file ",
0be3c7e @klacke untabified all of yaws
authored
76 {a,[{href, "json_sample.html"}], "json_sample.html"},
77 " and it is the HTML code that is the AJAX GUI !!!"]},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
78 {p, [], "Following that we need to take a look at the page "
0be3c7e @klacke untabified all of yaws
authored
79 "json_sample.yaws which is the \"serviceURL\" according to "
80 "the Javascript code. This code defines the function to be "
81 "called. Remember that the Javascript code defined one method, "
82 "called \"test1\", this information will be passed to the "
83 "serviceURL. The code looks like:"},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
84 ss(A, "json_sample.yaws"),
80f6d9f @klacke *** empty log message ***
authored
85
86 {p,[], "The two important lines on the server side are"},
87 {ol,[],
0be3c7e @klacke untabified all of yaws
authored
88 [
89 {li,[],
90 {pre,[],"yaws_rpc:handler_session(A2, {sample_mod, counter})."}},
91 {li,[],
92 {pre,[],"counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session)"}}]},
80f6d9f @klacke *** empty log message ***
authored
93
94 {p,[],
0be3c7e @klacke untabified all of yaws
authored
95 "The first line tells Yaws to forward all JSON-RPC methods to the "
96 " \"counter\" function in the \"sample_mod\" module. "
97 "The second line says, "
98 " basically, - this is the counter function that will be called when "
99 " the client invokes a method called 'test1'. We would duplicate "
100 " this line with a different name than 'test1' for each RPC function "
101 "we wish to implement."},
80f6d9f @klacke *** empty log message ***
authored
102
103 {p,[],"On the client side we have"},
104
105 box("
106 var methods = [ \"test1\" ];
107 var jsonrpc = imprt(\"jsonrpc\");
108 var service = new jsonrpc.ServiceProxy(serviceURL, methods);
109 "),
110
111 {p,[],"Which registers the Yaws page with the JSON-RPC handler and "
112 "gives it a list of methods that the Yaws page can satisfy. "
113 "In this case, it is only the method called 'test1'."},
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
114
80f6d9f @klacke *** empty log message ***
authored
115 {p, [],
116 "When we wish to return structured data - we simply let "
117 "the user defined RPC function return JSON structures such as "},
118
119 box(" {struct, [{field1, \"foo\"}, {field2, \"bar\"}]} "),
120 {p, [], " for a structure and "},
121 box("{array, [\"foo\", \"bar\"]}"),
122 {p, [],"for an array. We can nest arrays and structs in each other "},
123
0be3c7e @klacke untabified all of yaws
authored
124
80f6d9f @klacke *** empty log message ***
authored
125
126
127
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
128 {p, [],
0be3c7e @klacke untabified all of yaws
authored
129 "Finally, we must stress that this example is extremely simple. "
130 "In order to build a proper AJAX application in Yaws, a lot of "
131 "client side work is required, all Yaws provides is the basic "
132 "mechanism whereby the client side Javascript code, can RPC the "
133 "web server for data which can be subsequently used to populate "
134 "the DOM. Also required to build a good AJAX application is "
135 "good knowledge on how the DOM in the browser works"},
f7f7440 Added call to callback function: M:F(cookie_expire) which is expected…
Tobbe Tornquist authored
136
137 {p, [],
0be3c7e @klacke untabified all of yaws
authored
138 [{b,[],"Update:"},
139 "The yaws_rpc:handler will now also call: M:F(cookie_expire) which is "
140 "expected to return a proper Cookie expire string. This makes it possible "
141 "to setup the Cookie lifetime. If this calback function is non-existant, "
142 "the default behaviour is to not set a cookie expiration time, i.e it will "
143 "live for this session only."]}
47e5a7c @klacke JSON ajax code from Gaspar Chilingarov, I added docs describing an ex…
authored
144
145
146 ]}},
147
148 {ssi, "END2",[],[]}
149 ].
150
151
152
153
154 </erl>
155
156
157
158
159
160
161
Something went wrong with that request. Please try again.