Javascript 未为jquery定义获取未捕获引用错误:$
我正在尝试调用正在测试的本地api。我收到一个未捕获的引用错误:$未在调用中定义。下面是JS和html。在.js文件中定义查询是否有遗漏?在我做一些重构之前,它是可以工作的。我不确定我是否删除了我需要的东西,甚至没有注意到它 taskpane.jsJavascript 未为jquery定义获取未捕获引用错误:$,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试调用正在测试的本地api。我收到一个未捕获的引用错误:$未在调用中定义。下面是JS和html。在.js文件中定义查询是否有遗漏?在我做一些重构之前,它是可以工作的。我不确定我是否删除了我需要的东西,甚至没有注意到它 taskpane.js function domainWhois(domain){ var apiurl = 'http://localhost:5000/linkcheck'; console.log("entering domainWHois&qu
function domainWhois(domain){
var apiurl = 'http://localhost:5000/linkcheck';
console.log("entering domainWHois");
var request = {"link": domain};
$.ajax({
url: apiurl,
method: 'POST',
type: 'json',
data: JSON.stringify(request),
contentType: 'application/json',
crossDomain: true
}).done(
function(data){
console.log("successfully called API");
console.log(JSON.stringify(data));
}).fail(function(error){
console.log("api call failed");
console.log(JSON.stringify(error));
});
}
下面是HTML设置
!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contoso Task Pane Add-in</title>
<!-- Office JavaScript API -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" ></script>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
<!-- For more information on Office UI Fabric, visit https://developer.microsoft.com/fabric. -->
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/9.6.1/css/fabric.min.css"/>
<!-- AJAX-->
<!-- Template styles -->
<link href="taskpane.css" rel="stylesheet" type="text/css" />
<script src="taskpane.js" type="text/javascript"></script>
</head>
<body class="ms-font-m ms-welcome ms-Fabric">
<header class="ms-welcome__header ms-bgColor-neutralLighter">
<img width="90" height="90" src="../../assets/logo-filled.png" alt="Contoso" title="Contoso" />
<h1 class="ms-font-su">Welcome to your Email Security Assistant</h1>
</header>
<section id="sideload-msg" class="ms-welcome__main">
<h2 class="ms-font-xl">Please sideload your add-in to see app body.</h2>
</section>
<main id="app-body" class="ms-welcome__main" style="display: none;">
<div>
<h2>Secuirty Checks</h2>
<h3>Attachments</h3>
<p><label id="attachment-count"></label></p>
<p><label id="attachment-msg"></label></p>
<h3>Embedded Links</h3>
<p id="linkCheck"></p>
<h3>Header Checks</h3>
<p><label id="reply-match"></label></p>
<p><label id="dkimspfchk"></label></p>
<p><label id="domainMatch"></label></p>
</div>
</main>
</body>
</html>
!DOCTYPE html>
Contoso任务窗格加载项
欢迎使用您的电子邮件安全助理
请侧面加载外接程序以查看应用程序正文。
安全检查
附件
嵌入链接
标题检查
检查。它会解决你的问题。因为jquery已加载。因此,建议将外部脚本导入放在结束正文标记之前,它允许异步加载,而头标记中的加载是阻塞同步加载。检查。它会解决你的问题。因为jquery已加载。因此建议t将外部脚本导入放在结束正文标记之前,它允许异步加载,而头标记中的加载是阻塞同步加载。在第一行添加taskpane.js:var$=global.jQuery
我还怀疑jQuery.min.js没有加载,所以试着打开它:并保存为本地文件并附加到html中。我认为在加载jQuery之前,请阅读关于这个问题的答案:另外,建议将外部脚本导入放在结束正文标记之前,它允许异步加载,而head标记中的加载是阻塞同步加载。加载到taskpane.js的第一行:var$=global.jQuery
我还怀疑jQuery.min.js没有加载,所以尝试打开它:另存为本地文件并附加到html中。我认为加载jQuery之前的脚本,阅读关于这个问题的答案:还建议将外部脚本导入放在结束正文标记之前,它允许异步加载,而head标记中的加载是阻塞同步加载。