-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·195 lines (171 loc) · 7.15 KB
/
index.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<html>
<head>
<!--
*************************************
START OF STACKMOB JS SDK DEPENDENCIES
INCLUDE THESE IN YOUR PAGES WHERE YOU WANT TO USE THE STACKMOB JS SDK
*************************************
*************************************
*************************************
The following is optional:
<script type="text/javascript" src="http://static.stackmob.com/js/2.5.3-crypto-sha1-hmac.js"></script>
-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/json2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/underscore-1.3.3-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/backbone-0.9.2-min.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/2.5.3-crypto-sha1-hmac.js"></script>
<script type="text/javascript" src="http://static.stackmob.com/js/stackmob-js-0.5.2-min.js"></script>
<!--
*************************************
INITIALIZE THE JS SDK BELOW
COPY/PASTE THE INIT FROM:
https://stackmob.com/platform/help/tutorials/html5_js_sdk
*************************************
*************************************
*************************************
-->
<script type="text/javascript">
StackMob.init({
appName: "edhero",
clientSubdomain: "kennethng",
publicKey: "5f234f42-0b95-410e-8b53-58b67042f340",
apiVersion: 0
});
</script>
<script type="text/javascript">
function createuser(){
//Creating a user, but this time with a callback.
var user = new StackMob.User({ username: 'Bill Watterson', password: 'weirdosfromanotherplanet', profession: 'cartoonist' });
user.create({
//After StackMob successfully saves "Bill Watterson", print out the result
success: function(model) {
//Print out "Bill Watterson: cartoonist"
console.debug(model.get('username') + ': ' + model.get('profession'));
},
error: function(model, response) {
console.debug("curses! we have failed, Hobbes!");
}
});
}
</script>
<!--
*************************************
*************************************
*************************************
*************************************
END OF INIT
*************************************
*************************************
*************************************
*************************************
-->
<!--
*************************************
*************************************
*************************************
*************************************
STACKMOB JS SDK CODE THAT CREATES AND SAVES A TESTOBJECT
*************************************
*************************************
*************************************
*************************************
-->
<script type="text/javascript">
$(document).ready(function() {
//Define your class/object
var TestObject = StackMob.Model.extend({
schemaName : 'testobject' //Tell StackMob to save instances of TestObject to the table "testobject"
});
//Create a local instance of TestObject by passing JSON into the constructor
//We have several different field types here as examples.
//Fields must be lower case.
var to = new TestObject({
message : 'This test object instance will show you how StackMob creates your DB from JSON data',
integer : 1,
decimal : 2.5,
istestobject : true,
stringarray : ['This', 'is', 'an', 'array', 'of', 'strings'],
intarray : [1, 2, 3, 4, 5],
decimals : [1.1, 2.2, 3.3],
booleans : [true, false, true, false]
});
//Call "create" to fire off the AJAX call to StackMob to create this object instance
//If this is the first time StackMob has seen a 'testobject', StackMob will create the database schema automatically for you.
//When the server is done, AJAX callbacks are fired: 'success' / 'error'
to.create({
success : function(model) {
//Notice how StackMob auto generated a unique primary key for this object instance under "testobject_id".
//Schema primary keys are [schema name]_id
//If you specified "testobject_id" in your JSON, StackMob will use your given one instead.
console.debug(model.toJSON());
},
error : function(model, response) {
console.debug("Oops there was an error in creating the object.");
console.debug("Have you initialized your JS SDK?");
console.debug("Are you running this on StackMob's Local Runner?");
console.debug("Are you running this on StackMob's GitHub-integrated hosting?")
console.debug(response);
}
});
});
</script>
<!--
*************************************
*************************************
*************************************
*************************************
END CODE
*************************************
*************************************
*************************************
*************************************
-->
<title>Your First API Call</title>
<link href="http://www.stackmob.com/platform/favicon.ico" type="image/vnd.microsoft.icon" rel="icon" />
<link href="http://www.stackmob.com/platform/favicon.png" type="image/png" rel="icon" />
<link rel="stylesheet" href="styles/index.css" />
</head>
<body>
<input type="button" value="create user" onclick='createuser();'>
<h1>See above creating user!</h1>
<p id="runmessage">
Don't forget to <a href="https://stackmob.com/platform/help/tutorials/html5_js_sdk" target="_blank">initialize the JS SDK</a>!
<br/>
Please run this in <a href="http://www.stackmob.com/devcenter/docs/Local-HTML-Runner" target="_blank">StackMob's Local Runner</a> or through <a href="http://www.stackmob.com/devcenter/docs/StackMob-Hosted-HTML5:-GitHub" target="_blank">StackMob's GitHub-integrated hosting</a>.
</p>
<h2> You just ran your first JS SDK call! </h2>
<p>
It created a new schema in your server-side StackMob database named
<code>
testobject
</code>
.
</p>
<p>
<a href="https://www.stackmob.com/platform/api/schemas/edit/testobject" target="_blank" class="button">View your new testobject schema</a>
</p>
<p>
...and it also saved a
<code>
testobject
</code>
object - all in one call.
</p>
<p>
<a href="https://www.stackmob.com/platform/api/schemas/browser" target="_blank" class="button">View the Data</a>
</p>
<p>
View the source, then learn more!
<ul>
<li>
<a href="http://www.stackmob.com/devcenter/docs/JS-SDK-Tutorial" target="_blank">JS SDK Tutorial</a>
</li>
<li>
<a href="http://www.stackmob.com/devcenter/docs/Javascript-SDK-API" target="_blank">JS SDK API Docs</a>
</li>
</ul>
* all models and collections inherit from <a href="http://backbonejs.org/" target="_blank">Backbone.js</a> and hence share the same methods. Feel free to optionally <a href="http://backbonejs.org/" target="_blank">learn more about Backbone</a>!
</p>
</body>
</html>