I am getting information from a sharepoint list and then I want to use that data. The problem is that I need the data to be updated from the Sharepoint server before I use it, but I can't get executeQuery() to work. I can get executeQueryAsync() to work though. Here is my code:
// Global variables;
var context;
var web;
var list;
var howManyItem = 0;
var allItems;
var randNums = [];
// Initializes the variables; Sets listname; Gets all items;
function init(){
context = new SP.ClientContext.get_current();
web = context.get_web();
// Enter the list name;
this.list = web.get_lists().getByTitle('LetsTalkAdded');
// Get item count in the query/list;
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(Title)');
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
This works fine, but when I change the last line to:
context.executeQuery(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
It no longer works, but I can't run them asyncronously. If I do, the parts of my code that depend on that information don't work. Why doesn't the executeQuery() funcion work?
I am getting information from a sharepoint list and then I want to use that data. The problem is that I need the data to be updated from the Sharepoint server before I use it, but I can't get executeQuery() to work. I can get executeQueryAsync() to work though. Here is my code:
// Global variables;
var context;
var web;
var list;
var howManyItem = 0;
var allItems;
var randNums = [];
// Initializes the variables; Sets listname; Gets all items;
function init(){
context = new SP.ClientContext.get_current();
web = context.get_web();
// Enter the list name;
this.list = web.get_lists().getByTitle('LetsTalkAdded');
// Get item count in the query/list;
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(Title)');
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
This works fine, but when I change the last line to:
context.executeQuery(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
It no longer works, but I can't run them asyncronously. If I do, the parts of my code that depend on that information don't work. Why doesn't the executeQuery() funcion work?
Share edited Dec 22, 2014 at 16:50 pixelbobby 4,4405 gold badges31 silver badges50 bronze badges asked Aug 27, 2012 at 18:28 JoshJosh 411 gold badge1 silver badge2 bronze badges 3- The last line seems to be the same in both of your examples. – naivists Commented Aug 28, 2012 at 4:25
- no, they are different. executeQueryAsync vs executeQuery. – Senthil Kumar Commented Aug 28, 2012 at 7:08
- what do you mean my 'it no longer works'? what error message you get? – Senthil Kumar Commented Aug 28, 2012 at 7:09
2 Answers
Reset to default 6I have been trying something similar in using ExecuteQuery instead of the Async version. And from what I have found the non Async version is not supported in the JSOM. So you have to use the Async version.
Looking at his number 6. http://blogs.msdn./b/sharepointdev/archive/2011/07/19/working-with-the-ecmascript-client-object-model-jsom-in-sharepoint-2010-part-3-nikhil-sachdeva.aspx
executeQueryAsync cannot populate global variables. It's only use is to display an alert to the user. Other than that there is no use for it.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060348a4608928.html
评论列表(0条)