Skip to content

Commit 670c7d6

Browse files
authored
Update README.md
1 parent dc8a61c commit 670c7d6

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# Extension-jsapi
2-
Official extension to Diamond for a javascript api.
1+
# jsapi
2+
3+
Jsapi is an extension to views in Diamond, which extends views with an easy-to-use integration of js/jquery.
4+
5+
## extensions.config
6+
7+
```
8+
ViewExtension|jsapi|diamond.extensions.jsapi
9+
```
10+
11+
## API Docs
12+
13+
### void ajax(HTTPMethod method, string name, string url, string prepareFunction, string callbackFunction)
14+
15+
Requires: http://jquery.com/
16+
17+
This function will generate a javascript function that executes an ajax call through jquery.
18+
19+
Example:
20+
```
21+
<a href="#" onclick="authenticate()">Authenticate</a>
22+
23+
@:ajax(HTTPMethod.POST, "authenticate", "/login", "prepareAuth", "authenticated");
24+
25+
<script type="text/javascript">
26+
function prepareAuth() {
27+
var authArgs = {
28+
data: {
29+
username: 'test',
30+
password: '1234'
31+
},
32+
dataType: 'json'
33+
};
34+
35+
return authArgs;
36+
}
37+
38+
function authenticated(result) {
39+
if (result.success) {
40+
console.info(result);
41+
} else {
42+
console.error("An error happened during the request.");
43+
}
44+
}
45+
</script>
46+
```
47+
48+
*Note: You don't need to specify dataType if the dataType is json. The example above only has it for demonstration.*

0 commit comments

Comments
 (0)