1

I am unable to retrieve objects using the ClientContext.ExecuteQueryAsync method. Originally I was attempting to obtain a list item, but figured out that wasn't happening because I didn't really have a SPList. And that I didn't have a list because I didn't have a SPWeb. So I've simplified the code to do one thing: get a web. The results are the same in each case: no return from the asynchronous query. Nothing. It just disappears into the ether.

Here is the code, which is pretty much the standard routine I've found everywhere:

function getSelectedItems(
{
  alert('executing getSelectedItems');
  var clientContext = new SP.ClientContext.get_current();
  var spweb = clientContext.get_web();
  alert('Web id: ' + spweb.get_id());
  clientContext.load(spweb);
  clientContext.executeQueryAsync(
       Function.createDelegate(this,this.onWebQuerySucceeded), 
       Function.createDelegate(this, this.onWebQueryFailed));
}

function onWebQuerySucceeded() 
{
   alert('Query succeeded');
}

function onWebQueryFailed(sender, args) 
{
   alert('Query failed');
}

ExecuteOrDelayUntilScriptLoaded(getSelectedItems, 'sp.js');

I am getting the current web: the alert does display an id. But neither the onWebQuerySucceeded function nor the onWebQueryFailed function function ever get invoked. I ran a web trace using Fiddler and here are the three web requests the trace captures:

GET /pki/mscorp/crl/Microsoft%20Secure%20Server%20Authority(7).crl HTTP/1.1
Cache-Control: max-age = 900
Accept: */*
If-Modified-Since: Thu, 06 Jan 2011 18:47:54 GMT
If-None-Match: "4df22d3ad2adcb1:0"
User-Agent: Microsoft-CryptoAPI/6.1
Connection: Keep-Alive
Host: mscrl.microsoft.com


HTTP/1.1 304 Not Modified
Content-Type: application/pkix-crl
Age: 164
Date: Wed, 19 Jan 2011 18:15:40 GMT
Expires: Wed, 19 Jan 2011 18:27:56 GMT
Connection: keep-alive


------------------------------------------------------------------
GET /pki/mscorp/crl/Microsoft%20Secure%20Server%20Authority(5).crl HTTP/1.1
Cache-Control: max-age = 900
Accept: */*
If-Modified-Since: Thu, 06 Jan 2011 18:48:25 GMT
If-None-Match: "b409c4cd2adcb1:0"
User-Agent: Microsoft-CryptoAPI/6.1
Connection: Keep-Alive
Host: mscrl.microsoft.com


HTTP/1.1 304 Not Modified
Content-Type: application/pkix-crl
Age: 307
Date: Wed, 19 Jan 2011 18:15:40 GMT
Expires: Wed, 19 Jan 2011 18:25:33 GMT
Connection: keep-alive


------------------------------------------------------------------
GET /pki/mscorp/crl/mswww(5).crl HTTP/1.1
Cache-Control: max-age = 900
Accept: */*
If-Modified-Since: Fri, 17 Dec 2010 19:39:40 GMT
If-None-Match: "0662d25229ecb1:0"
User-Agent: Microsoft-CryptoAPI/6.1
Connection: Keep-Alive
Host: mscrl.microsoft.com


HTTP/1.1 304 Not Modified
Content-Type: application/pkix-crl
Age: 416
Date: Wed, 19 Jan 2011 18:15:40 GMT
Expires: Wed, 19 Jan 2011 18:23:44 GMT
Connection: keep-alive


------------------------------------------------------------------

I'm at a complete loss. I'm developing against a SharePoint 2010 Foundation instance. Any help would be appreciated.

2 Answers 2

1

Following on from James's post who makes a good point.

I think its because you have this keyword in front of each delegate function, so when the callback is called it can't find the function to call back into.

Change:-

clientContext.executeQueryAsync(Function.createDelegate(this,**this**.onWebQuerySucceeded), Function.createDelegate(this, **this**.onWebQueryFailed));

to

clientContext.executeQueryAsync(Function.createDelegate(this,onWebQuerySucceeded), Function.createDelegate(this, onWebQueryFailed));

Just so you know the function for the successful and failed functions should have the following function arguments.

function onWebQuerySucceeded(sender, args) {

}

function onWebQueryFailed(sender, args) {

}

Let us know how you get on.

Regards Simon

0

Not sure if this matters, but your web succeeded delegate doesn't have any parameters (so it might not "match the delegate prototype", if such a thing in JavaScript exist).

1
  • This is not relevant. In JavaScript, when signature doesn't match the extra arguments are still available in the arguments array. Mar 19, 2014 at 6:12

Your Answer

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