在第一次加载页面时,JSOM以匿名模式禁止应用程序(重新加载解决了它)

时间:2016-05-20 10:36:40

标签: sharepoint sharepoint-apps sharepoint-jsom

我在发布网站的页面上有一个应用程序部分。 在该应用程序中,JSOM调用在用户通过身份验证时运行良好。 在匿名模式下,只有在重新加载包含应用程序部分的页面后,它才会起作用。在第一次加载期间,我将收到此错误:

无法加载资源:服务器响应状态为403(FORBIDDEN) http://app-4e3210d8daa297.abc.com/MyList/_vti_bin/client.svc/ProcessQuery

JSOM调用的错误处理程序返回" undefined"错误信息。

但是,如果我重新加载页面,或者应用程序部分本身(使用javascript代码),那么它可以正常工作。

为什么仅在第一次加载页面时才禁止JSOM调用?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是暂时解决此问题的快速解决方法,但我确信有更好的方法。

    //error handler of the jsom call that fails
    function onErrorLoadList(data, error, errorMessage) {
        console.log("Could not complete cross-domain call: " + errorMessage);
        // in anonymous mode, for the first load of the app
        // the JSOM calls fail and errorMessage is undefined
        if (typeof errorMessage == 'undefined') {
            // we will reload the app by adding reload=true in the url
            // if it fails again, we won't do it to avoid a loop
            if (!location.href.match(/reload=true/)) {
                console.log("The app reloads.");
                location.href = location.href + "&reload=true";
            }
        }
    }
相关问题