When I access a specific page I have at the start of a day, no data will show. After I refresh the same page, the data appears as it should. If I were to access the same page an hour later the data will still be shown. However, come the next day, the same will happen. No data when I access the page first time, but it comes after a refresh.
The page in question uses a jquery script with an ajax call.
The script itself is used in a Sharepoint 2010 environment and uses ListData.svc to fetch data (name, id, type and soforth), and getting the actual data doesn't seem to be an issue (at least when I refresh).
Anyone have an idea why this could be happening?
The code:
<script type="text/javascript">
$(document).ready(function () {
function getUrlVars() {
var vars = [], hash;
var hashes = window.parent.location.href.slice(window.parent.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var pTypeval = getUrlVars()["projectType"];
$('#projTypeHeader').append(unescape(pTypeval));
$.ajax({
url: "/../Projects/1/_vti_bin/ListData.svc/Projectlist?$select=ID,Projectname,ProjectTypeValue,ProjectHeading,PublishInfoscreen&$filter=(ProjectTypeValue%20eq%20%27" + pTypeval + "%27)%20and%20(PublishInfoscreen%20eq%20true)",
method: "GET",
dataType: "JSON",
headers: { "accept": "application/json; odata=verbose" },
success: function (data) {
$('#projectRow').empty();
$.each(data.d.results, function (index, item) {
var itemExist = false;
$.each($('.projectRow').find('h1'), function (index1, item1) {
if (item1.innerHTML == item.ProjectHeading) {
itemExist = true;
$(item1).parent().append("<h3><a id=" + item.ID + " class='projectLink' href='javascript:void(0)'>" + item.Projectname+ "</a></h3>");
}
});
if (itemExist == false)
$('.projectRow').append("<div class='projectHeadingDiv left'><li><h1>" + item.ProjectHeading + "</h1><h3><a id='" + item.ID + "' class='projectLink' href='javascript:void(0)'>" + item.Projectname+ "</a></h3></div>");
});
},
error: function (error) {
alert(JSON.stringify(error));
}
});
});
</script>
Update: As per the comments, I tried moving the function getUrlVars() outside the document.ready, this did not help. However, I tried using a different browser this morning and on the first fetch I got this error:
Site on intranet says: {"readyState":4,"responseText":"{\r\n\"error\": {\r\n"code\": \"\", \"message\": {\r\n\"lang\": \"en-US\", \"value": \Type 'Microsoft.Sharepoint.DataService.ProjectlistItem' does not have a property named 'ID'. \"\r\n}\r\n}\r\r}","status": 400,"statusText":"error"}
Refreshed the page and the data appears. It would seem like on the first GET, it can't find the items in the list, but after a second GET, it works just fine. Any suggestions why this could be?