Much has been written about the Client Object Model of SharePoint 2010 so I don't want to bore you with another post about that.
I would like to write something about JavaScript, SharePoint 2010, Web 2.0 and, why not!, how to use Knockout in SharePoint… WOW
So let’s start why a little about theory about COM.
One image a thousand words:
I got this image from MSDN off-course!!!
We will focus ourselves in what the red-square contains.
JavaScript OM
With JavaScript OM you can working inside the client browser to build new categories of application, for example rich html-javascript web part or form.
With JavaScript you work in a unmanaged area and you can use this om when you are working with the Server ribbon or insde sandboxed solutions.
Client.svc
It’s one of web services provided by Microsoft SharePoint 2010.
The following table lists and describes the available web services: http://msdn.microsoft.com/en-us/library/ee538665.aspx
Ok now I show you a simple example:
- This is the result:
- and this is the code
<script type="text/javascript">
var context = null;
var web = null;
var currentUser = null;
function getUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this.oCurrentUser = web.get_currentUser();
context.load(this.oCurrentUser);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
var today = new Date();
alert('User Name:' + this.oCurrentUser.get_title() + '\n Login Name:' + this.oCurrentUser.get_loginName() + '\n Page URL:' + location.href);
}
function onFaiureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
function callUserData() {
ExecuteOrDelayUntilScriptLoaded(getUserData, "sp.js");
}
</script>
<input type="button" value="Get User Info" onclick="javascript:callUserData();" />
ok it’s nothing special but this post is useful for the next one where we will create our service…
see you guys!
No comments:
Post a Comment