I hope this is the right place
I have been in a role within my organization working with SharePoint for a couple of months now, so i'm a newb more or less. I have some experience (again a novice) with coding (JavaScript/Jquery). So i'm assuming that i'm missing something minor that is causing this.
The Question: I have built a few Web Pages and Web Parts that are using REST to pull information in, and am managing that information via jQuery/JavaScript and using CSS. It works, as expected, however on occasion the page will not fully load the code (the main HTML and CSS shows but the code does not execute). But if we come back to it a few days later - it works again with no issues. I have also created another page for the same code (when one doesn't work, the other generally will).
So i'm wondering if possibly my code (Java or jQuery) is casing the issue (too much information in the cache or something). And should i empty my strings once done with them in the code, or is their something else i possibly might want to check into?
Using: Sharepoint 2013, jQuery 1.10, CSS, HTML, am including the .html using a Content Editor part. User base is Chrome, and IE (back to 9 I think).
When the document loads the first thing it does is pull the users for the sharepoint in, then loads their names and id's into an array. After its complete it then calls the GetMainBoard Function
$(document).ready(function() {
//the users for the sharepoint are pulled into an array that consists of only the user ID and Name
$.ajax({
"url": "<SharePoint>/_vti_bin/ListData.svc/UserInformationList",
"method": "GET",
"headers": {
"accept": "application/json; odata=verbose"
},
"success": function (data) {
data.d.results.forEach(function(a){
//this loads the users found in the sharepoint into an array, it does not attempt to validate if the user already exists in the array, as each name in the sharepoint list has an idea (so if multiples exist it may assign a secondary number).
UserLookup.push([{Id : a.Id, Name : a.Name}])
})
;$(this).GetMainBoard();
//the main board function is called
}})
});
The Main Board function, pulls the list that its working with, and extracts the teams names for that list (there are multiple lists that the code works with).
$.fn.GetMainBoard = function() {
//This sets the array to nothing, blanking the array if any content exists.
xTeamName.length = 0;
$.ajax({
"url": "<Sharepoint>/_api/Web/Lists/getByTitle('"+SrcList+"')/Items?$top=1000&$Select=Team&$orderby=Team asc",
"method": "GET",
"headers": {
"accept": "application/json; odata=verbose"
},
"success": function (data) {
data.d.results.forEach(function(a){
//This calls the team names from the sharepoint list, it then checks the list against the array, and if it doesnt exist it adds it.
if($.inArray(a.Team,xTeamName) === -1){
xTeamName.push(a.Team); }
})
$(this).RunList();
}});
}
The RunList function determines which amount of information to pull from the list (there is a "short view" and a "full view" of the information that is pulled). There is no rest in this function, as all it does is passes the call to another function depending on the view type.
After this, another function is called that pulls the main content down from the list. It adds the html and content to a string and then $('.MainContent').append(content) writes the information to the DOM.
Thank you for the help so far, and let me know if i need to add anything additional!
<script>
tags, or are you using<script src="/path/to/file.js">
to link in the code from another file?