4

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?

Moti Korets
  • 3,738
  • 2
  • 26
  • 35
user3463093
  • 177
  • 1
  • 6
  • try to put `getUrlVars()` function outside `document.ready` – Amit Soni Jun 15 '14 at 12:34
  • My guess would be the server goes to sleep at night and you waking it up in the morning but the first call gets a timeout. Can you post what the error response ? – Moti Korets Jun 15 '14 at 15:26
  • Thank you for responses. I am unable to get the error response until tomorrow morning, but I will post here once I have it. I will also try to put the getUrlVars() function outside of document.ready. – user3463093 Jun 15 '14 at 19:31
  • @MotiKorets I have updated the original post with the error message I got – user3463093 Jun 16 '14 at 08:02
  • 3
    So it seems your problem is have more to do with SharePoint than with jQuery. I'll suggest tag the question appropriately. Check the server for any sleep configuration. – Moti Korets Jun 16 '14 at 11:58
  • Please check the Caching: is the jquery lib cached for ONE day ? if yes it means that after getting it (first time) you no more load it the whole day. How/where in your page do you load the jquery lib ? – Emmanuel Gleizer Jun 24 '14 at 14:48

1 Answers1

0

SharePoint app pools recycle every night. Because of this, the first hit of the day on a SharePoint site can take some time for everything to spin up. Some people run this powershell script to continuously keep the SP server active. This should resolve the lag on the webservice you are hitting in the mornings.

http://blogs.technet.com/b/praveenh/archive/2013/03/12/sfsgfasg.aspx

RandomDeduction
  • 565
  • 1
  • 5
  • 17