I created a test custom .aspx page in sharepoint 2010 and I want to get client object model (javascript) working on it, without loading the master page.
However when I load the page, I get this error:
[10:47:22.513] ReferenceError: FV4UI is not defined @ http://XXXX/_layouts/1033/core.js:2
[10:47:24.882] ReferenceError: IEnumerator is not defined @ http://XXXX_layouts/sp.runtime.js:2
[10:47:28.247] TypeError: SP.ScriptUtility is undefined @ http://XXXX/_layouts/sp.js:2
This is what I have so far:
<!DOCTYPE HTML>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
<%-- <SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name="core.js" runat="server" /> --%>
<%-- <SharePoint:ScriptLink language="javascript" name="SP.js" defer="true" runat="server" Localizable="false"/> --%>
</head>
<body>
<form id="form1" runat="server">
</form>
<script type="text/javascript" src="./includes/js/jquery/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="/_layouts/1033/core.js"></script>
<script type="text/javascript" src="/_layouts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/1033/init.js"></script>
<script type="text/javascript" src="/_layouts/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/sp.js"></script>
<!-- <script type="text/javascript" src="/_layouts/sp.taxonomy.js"></script> -->
<script type="text/javascript">
// occurs when the document is ready
$(document).ready(function() {
alert(1);
// wait for the sharepoint javascript libraries to load, then call the function 'Initialize'
ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
alert(2);
});
var listItems; // The list of retrieved items.
var query; // For paging, reuse the same query object.
var targetList; // The list from which to retrieve items.
var clientContext;
function runCode() {
clientContext = new SP.ClientContext();
web = clientContext.get_web();
targetList = web.get_lists().getByTitle("Documents");
query = new SP.CamlQuery();
var CAML = "<View><Query><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy></Query></View>";
var CS = "Include(Title,FileRef)";
//Specifying the RowLimit will determine how many items will be fetched in one call to the server.
query.set_viewXml(CAML);
listItems = targetList.getItems(query);
clientContext.load(listItems,CS);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var message = "Titles, two at a time:\n";
var listEnumerator = listItems.getEnumerator();
while (listEnumerator.moveNext()) {
message += "\nTitle=" + listEnumerator.get_current().get_item("Title")
}
alert(message);
//Gets the id of the last element from the returned collection along with the query.
var position = listItems.get_listItemCollectionPosition();
//Position will be null if all the items in the collection are fetched and there are no more items to be fetched.
if (position != null) {
//If more items are to be fetched, make a second call to the server and fetch the next group of items.
query.set_listItemCollectionPosition(position);
listItems = targetList.getItems(query);
clientContext.load(listItems);
//Call the same function recursively until all the items in the current criteria are fetched.
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
}
}
function onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>
</body>
</html>