Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Getting list items based on ODATA Query
- function getListItems(url, listname, query, complete, failure) {
- // Executing our colors ajax request
- $.ajax({
- url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
- complete(data); // Returns JSON collection of the results
- },
- error: function (data) {
- failure(data);
- }
- });
- }
- $filter=AuthorId eq <UserId>
- function getCurrentUser(url,complete, failure)
- {
- $.ajax({
- url: url + "/_api/web/currentUser",
- method: "GET",
- headers: { "Accept": "application/json; odata=verbose" },
- success: function (data) {
- complete(data.d);
- },
- error: function (data) {
- failure(data);
- }
- });
- }
- function getMyListItems(url, listname,complete, failure) {
- getCurrentUser(url,
- function(user){
- var query = '?$filter=AuthorId eq ' + user.Id;
- getListItems(url,listname,query,complete,failure);
- },
- failure
- );
- }
- $.ajax(
- {
- url: url,
- type: "GET",
- contentType: "application/json;odata=verbose",
- headers: { "Accept": "application/json;odata=verbose" },
- success: function (data) {
- var result = data.d.results;
- for (var i = 0; i < result.length; i++) {
- alert(result[i].FirstName);
- alert(result[i].LastName);
- }
- }
- error: function (err) {
- alert(JSON.stringify(err));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement