JQuery script not working for the first time

When I access a specific page that I have at the beginning of the day, the data is not displayed. After I refresh the same page, the data will appear as it should. If I got access to one page in an hour, the data would still be displayed. However, the next day, the same thing will happen. There is no data at the first access to the page, but it appears after the update.

This page uses a jquery script with ajax call.

The script itself is used in Sharepoint 2010 and uses ListData.svc to retrieve data (name, identifier, type, and so on), and getting the actual data does not seem to be a problem (at least when I update).

Does anyone have an idea why this could happen?

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: , getUrlVars() document.ready, . , , :

: { "readyState": 4, "responseText": "{\ r\n \" error\ ": {\ r\n" code\": \ "\", \ "message \": {\ r\n\ "lang \":\ "en-US \",\ "":\ "Microsoft.Sharepoint.DataService.ProjectlistItem" "ID". \ "\ \}\\}\\}", "": 400, " ": "" }

​​ . , GET , GET . , ?

+4
1

SharePoint . - , SharePoint , . powershell script, SP-. -, .

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

0

Source: https://habr.com/ru/post/1544643/


All Articles