I am trying to implement to Sharepoint simple function from MSDN which I've placed in aspx file but I got this error in js web browser console: Uncaught ReferenceError: SP is not defined. Any ideas how to solve it?

<script src="https://ajax.aspnetcdn.com/ajax/4.0/MicrosoftAjax.js"  type="text/javascript"></script>
<script type='text/javascript'>
   function retrieveWebSite(siteUrl) {
       var clientContext = new SP.ClientContext(siteUrl);
       this.oWebsite = clientContext.get_web();


           Function.createDelegate(this, this.onQuerySucceeded),
           Function.createDelegate(this, this.onQueryFailed)

   function onQuerySucceeded(sender, args) {
       alert('Title: ' + this.oWebsite.get_title() +
           ' Description: ' + this.oWebsite.get_description());

   function onQueryFailed(sender, args) {
       alert('Request failed. ' + args.get_message() +
           '\n' + args.get_stackTrace());
   window.onload = retrieveWebSite;
<h1>Hello world</h1>

1 Answer 1


Call your function on,

For SharePoint 2010,

ExecuteOrDelayUntilScriptLoaded(functionName, "sp.js");

For SharePoint 2013,

SP.SOD.executeFunc('sp.js', function () { 
// code goes here


SP.SOD.executeFunc("sp.js", functionName);

the problem is that the file sp.js, is not reffered and hence not getting loaded before the function call. That file contains the class whose object you have reffered. (ie - SP)

  • I've tried both youor examples for SP2013 but error still occures.
    – arth81
    Dec 4, 2015 at 13:40
  • This does not give an answer. You can post your own question
    – Asad Refai
    Dec 4, 2015 at 13:44
  • Yeah you are right Asad Refai. Please post the question bud. Try debugging your code. Dec 4, 2015 at 13:45
  • I am new to SP. Maybe I should give full reference to the sp.js file somehow?
    – arth81
    Dec 4, 2015 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.