JSOM异步页面返回“未知错误". [英] JSOM async page returns "Unknown Error"

查看:112
本文介绍了JSOM异步页面返回“未知错误".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在针对Sharepoint Office 365环境使用JSOM在现有站点上创建新页面时遇到问题.我设法提取并创建创建页面所需的所有信息,但是在加载"newPage"后进行异步调用时, 它返回未知错误";没有进一步的解释.

I'm having issues creating a new page on an existing site using JSOM against a Sharepoint Office 365 environment. I manage to extract and create all of the information that I need to create the page, but when I make the async call after loading "newPage" it returns "Unknown Error" with no further explanation. 

// Create and load all of the elements that is needed if we want to create new pages.
    try {
        var info = _spFriendlyUrlPageContextInfo;
    } catch (e) {
        // This is possibly the home page.
        l.onclick = function () {
            alert("If you are on the home page, use the ribbon to add a new page. If not, please contact the administrator.")
        }
        return;
    }
    var context = SP.ClientContext.get_current();
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
    var termStores = taxSession.get_termStores();
    var termStore = termStores.getById(info.termStoreId);
    var termSet = termStore.getTermSet(info.termSetId);
    var parent = termSet.getTerm(info.termId);
    var web = context.get_web();

    context.load(termStore);
    context.load(parent);
    context.load(web);

    context.executeQueryAsync(function () {
        // We have everything loaded.
        // Add the correct clickHandler to the link.
        var link = document.getElementById('createChildPage');  
        link.onclick = function () {
            var title = prompt("Please enter the title of the new page");
            if (title != undefined && title != "") {
                // We have a name, now sanitize it.
                title = sanitizeName(title);
                // Create the page and taxonomy.
                var newPublishingPage = SP.Publishing.PublishingWeb.getPublishingWeb(context, web);
                var pageTemplate = web.getFileByServerRelativeUrl(_spPageContextInfo.siteServerRelativeUrl + "/_catalogs/masterpage/EnterpriseWiki.aspx");
                context.load(web);
                context.load(newPublishingPage);
                context.load(pageTemplate);
                context.executeQueryAsync(
                    function () {
                        // Loaded web and newPublishingPage
                        var pageInfo = new SP.Publishing.PublishingPageInformation();
                        pageInfo.set_name(title);
                        pageInfo.set_pageLayoutListItem(pageTemplate);
                        var newPage = newPublishingPage.addPublishingPage(pageInfo);

                        context.load(newPage);
                        context.executeQueryAsync(
                            // On Success
                            function () { alert("Done"); },
                            // On Error
                            function (sender, args) {
                                console.error("Failed to create page");
                                console.error(args.get_message());
                            });
                    }
                    , function () {
                        console.error("Failed to create publshing page");
                        console.error(args.get_message());
                    });
            }
        }
    }, function (sender, args) {
        console.error(sender);
        console.error(args);
    });

我正在使用的EnterpiseWiki模板进行了稍微修改,但是使用其他模板会产生相同的错误.

The EnterpiseWiki template that I'm using is slightly modified, but using other templates produces the same error. Is there any way for me to discern the issue in the code or is it an error on the sharepoint side? 

推荐答案

Hi ,

如果您想从母版页画廊的页面布局中创建发布页面,请参考以下工作代码示例:

If you want to create a publishing page from master page gallery pagelayout, here is a working code sample for your reference:

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>  
<script language="javascript" type="text/javascript">


(document).ready(function(){ var scriptbase = _spPageContextInfo.webServerRelativeUrl +``/_layouts/15/";
(document).ready(function() { var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";


.getScript(scriptbase +"SP.Runtime.js",function(){
.getScript(scriptbase + "SP.Runtime.js", function() {


这篇关于JSOM异步页面返回“未知错误".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆