0

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

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

JSOM 调用的错误处理程序返回“未定义”错误消息。

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

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

4

1 回答 1

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";
            }
        }
    }
于 2016-05-23T10:33:26.993 回答