我用react开发office add-in,定义了一个从服务器获取数据的函数。 服务器收到请求并做出成功响应。 但请求没有得到回应 我错过了什么或做错了什么吗?
async function sendRequest() {
const param = "abb";
var res = await myRequest(param);
return Word.run(async (context) => {
const doc = context.document;
const originalRange = doc.getSelection();
originalRange.insertText(res.data, Word.InsertLocation.before);
await context.sync();
});
}
function myRequest(payload) {// the same as the example in Microsoft document
const url = `http://127.0.0.1:8080/complete/keyword?text=${payload}`;
return new Promise(function (resolve, reject) {
fetch(url)
.then(function (response) {
return response.json();
})
.then(function (json) {
resolve(JSON.stringify(json.names));
});
});
}