I keep receiving the error message "SP.ClientContext is not a Constructor" every time I try to use it in my JS code. After doing a bit of research online, I found SP.SOD.execute function(). However, I can't figure out if I am using it wrong, or if there may be another problem with my code. I created a simple .ASPX page in SharePoint to test this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://ift.tt/mOIMeg">
<%@ Page language="C#" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=XXX" %>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>
<html xmlns="http://ift.tt/lH0Osb">
<script>
var siteUrl = [MY URL];
function test(){
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems());
}
function retrieveListItems() {
try{
var clientContext = new SP.ClientContext(siteUrl);
...
}catch(err){
alert(err.message);
}
</script>
<head>
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<input type="button" value="Click Me!" onclick="test();"/>
</head>
<body>
</body>
</html>
I've tried using jQuery, as well, but this still didn't help me:
$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(retrieveListItems(), "sp.js");
Any suggestions?

0 commentaires:
Enregistrer un commentaire