Created
August 28, 2012 22:21
-
-
Save ardok/3504865 to your computer and use it in GitHub Desktop.
This a doc for StackMob's JS SDK custom code (docs javascript-sdk-api)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## customcode | |
**Introduced:** JS SDK Version 0.1.0 | |
**Updated Signature:** JS SDK Version 0.6.0 | |
**Description:** | |
```javascript | |
customcode(customcodeName, customcodeParameters, method, options) | |
customcodeName - the name of your custom code method | |
customcodeParameters - a hash of parameters you are passing to your custom code | |
method - either 'GET', 'POST', 'PUT', or 'DELETE'. You can call customcode without method param: customcode(customcodeName, customcodeParameters, options) and the method param will be set to default ('GET'). | |
options - a hash containing, but not limited to "success" and "error" callbacks | |
``` | |
StackMob gives you the ability to write and upload server side code that you can execute from the client side. This uses our <a href="http://www.stackmob.com/devcenter/docs/Getting-Started:-Custom-Code-SDK" target="_blank">Custom Code SDK</a>. | |
e.g. If you write a Java/Scala method named `getloggedinuser` and upload it to StackMob, you can call that server-side code from your client-side JS SDK and return value of your Java/Scala method. | |
**Usage:** | |
```javascript | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<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/stackmob-js-0.5.5-min.js"></script> | |
<script type="text/javascript"> | |
/* <![CDATA[ */ | |
StackMob.init({ | |
appName: 'your_app_name', | |
clientSubdomain: 'your_client_subdomain', | |
publicKey: 'your_public_key', | |
apiVersion: 0 | |
}); | |
/* ]]> */ | |
</script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
/* <![CDATA[ */ | |
/* | |
The following example assumes you've uploaded custom code to StackMob's servers, running your code in a JVM server-side. | |
It assumes you have a method named "helloworld" that can take a parameter "who" | |
The server-side code simply returns "Hello World, Kodi!" | |
*/ | |
StackMob.customcode('helloworld', | |
{ who: "Kodi" }, //method parameters | |
'GET', //skip third param for default 'GET'. This can also be either 'POST', 'PUT', or 'DELETE' | |
{ | |
success: function(result) { | |
console.debug(result); //prints out the returned JSON your custom code specifies | |
/* | |
{ | |
msg: "Hello World, Kodi!" | |
} | |
*/ | |
} | |
} | |
); | |
/* ]]> */ | |
</script> | |
</body> | |
</html> | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment