在某些文档上出现500错误,而在其他文档上却没有。为什么?

时间:2019-03-01 00:21:28

标签: ajax post office-js word-addins

我的MS Word加载项适用于某些文档,但不适用于其他文档。对于test-doc-A,它可以正常工作。我得到想要的结果。 test-doc-B在$ .ajax调用上引发500错误,该调用将文本发送到服务器。两个文档都是一页。当然,应该将500个错误视为“服务器”端。但是,导致这些问题的这些文档之间可能有何不同?

(在我看来)服务器日志中没有任何内容可以告诉我问题所在。

test-doc-A (All Good)
2019-02-28 23:41:33 MyApiEndPoint POST /api/Document/Upload X-ARR-LOG-ID=8b253a46-bca8-4981-9ded-3fdf671fe63c 443 - myIpAddressMozilla/5.0+(Windows+NT+10.0;+WOW64;+Trident/7.0;+Touch;+rv:11.0)+like+Gecko - https://localhost:44399/Home.html?_host_Info=Word$Win32$16.01$en-US myServerUrl 200 0 0 664 3793 46

test-doc-B (500 Error)
2019-02-28 23:42:13 MyApiEndPoint POST /api/Document/Upload X-ARR-LOG-ID=b0095aa0-9fc5-4a26-83b0-40d44ff160ba 443 - myIpAddress Mozilla/5.0+(Windows+NT+10.0;+WOW64;+Trident/7.0;+Touch;+rv:11.0)+like+Gecko - https://localhost:44399/Home.html?_host_Info=Word$Win32$16.01$en-US myServerUrl 500 0 0 326 11306 46

是否可以比较发送的文本?我在使用正确的方法'range.load(“ text”)'吗?

文档之间的唯一区别似乎是格式。但是,我只是发送文本,而不管格式如何,不是吗?

在发送之前,我需要“清除”文本吗?真是太困惑了,现在。

function sendTextToServer() {
   Word.run(function (context) {
    var doc = context.document;
    var range = doc.body;

    range.load("text");

    return context.sync()

        .then(function () {
            var myData = '{\"FileName\": \"WordAddIn-Test\",\"Text\": \"' + range.text + '\" }';

            // begin promise
            var promise = $.ajax({
                url: urlToUse + "/Upload",
                method: 'POST',
                contentType: 'application/json; charset=utf-8',
                beforeSend: function (request) {
                    request.setRequestHeader("Authorization", "Negotiate");
                },
                crossDomain: true,
                dataType: 'json',
                processData: false,
                cache: false,
                data: myData,
                success: function (data) {
                    log("sendTextToServer Success: " + JSON.stringify(data));
                },
                error: function (xhr, textStatus, errorMessage) {
                    log("sendTextToServer promise Error: " + errorMessage + "  : " + JSON.stringify(xhr) + "  : " + textStatus);
                }
            });
            // end promise

            // do something with promise
            promise.done(function (data) {
                myDocID = data.documentID;
                log("sendTextToServer myDocID: " + myDocID);
                log("url = " + urlToUse + "/Status?documentID=" + myDocID);
                setTimeout(function () { goDoSomethingElse(); }, 2000);
            });
        })
        .then(context.sync);
   }).catch(function (error) {
        log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            log("Debug info: " + JSON.stringify(error.debugInfo));
            log("Something went wrong. Trying again");
        }
    });
}

“好像我选错了一周来退出嗅探胶。”    〜史蒂夫·麦克罗斯基

0 个答案:

没有答案