Javascript Word Office JS加载项-获取请求-对象不';t支持属性或方法';应用';

Javascript Word Office JS加载项-获取请求-对象不';t支持属性或方法';应用';,javascript,ajax,ms-word,office-js,word-addins,Javascript,Ajax,Ms Word,Office Js,Word Addins,我正在尝试使用ajax请求通过Word Office JavaScript插件从Web API获取一些数据。但是,我在打电话时遇到以下错误: 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“应用” 这是我的密码: Office.onReady(function () { // Office is ready $(document).ready(function () { // The document is re

我正在尝试使用ajax请求通过Word Office JavaScript插件从Web API获取一些数据。但是,我在打电话时遇到以下错误:

0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“应用”

这是我的密码:

Office.onReady(function () {
        // Office is ready
        $(document).ready(function () {
            // The document is ready
            // Use this to check whether the API is supported in the Word client.
            if (Office.context.requirements.isSetSupported('WordApi', '1.1')) {

                $('#rooms').click(Word.run(function (context) {
                    $.ajax({
                        url: "http://localhost/soundtestingsoftware/public/api/projects/27/rooms",
                        type: "GET",
                        success: function (result) {
                            var doc = context.document.getSelection();
                            doc.insertText(JSON.stringify(result), Word.InsertLocation.start);
                            return context.sync();
                        },
                        error: function (err) {
                            console.log(err);
                        }
                    });
                }));

                $('#supportedVersion').html('This code is using Word 2016 or later.');
            }
            else {
                // Just letting you know that this code will not work with your version of Word.
                $('#supportedVersion').html('This code requires Word 2016 or later.');
            }
        });
    });

我已将AppDomain添加到清单文件中。有人能告诉我为什么会发生这个错误吗?谢谢

您是否在
错误
回调中看到此错误?另外,尝试将端口添加到
http://localhost
并尝试使用https而不是http。@RickKirkham我已通过在my Home.html文件中包含最新的jquery cdn修复了此错误。现在代码运行时没有错误,但是我的ajax请求没有工作,因为它没有从服务器检索任何数据。当我运行代码时,不会发生任何事情。我已将端口添加到,但运气不佳。还有其他想法吗?使用Fiddler工具查看$.ajax调用的请求和响应。@RickKirkham在Fiddler中,我得到一个200响应,它返回我期望的JSON。然而,什么也没有发生。当我运行程序时,这会在Fiddler中运行,而不是当我单击UI中的“#rooms”按钮时。您的代码正在调用
Word。请运行
函数,而不是将其分配给click事件。请将
字封装起来。将
运行到命名函数中,然后将函数名分配给单击事件。有关示例,请参见工具中的示例。