javascript - ReferenceError:未定义“$”
问题描述
出现错误 ReferenceError: "$" 未定义。运行以下功能时。我在 Google API 控制台和高级 Google 服务中都启用了 Sheets API
function createTriggers2() {
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>;
var settings = {
"async": true,
"crossDomain": true,
"url": "http://api.msg91.com/api/v2/sendsms",
"method": "POST",
"headers": {
"authkey": "My_auth_key",
"content-type": "application/json"
},
"processData": false,
"data": "{ \"sender\": \"SOCKET\", \"route\": \"4\", \"country\": \"91\", \"sms\": [ { \"message\": \"Message1\", \"to\": [ \"96xxxxx\", \"70xxxxx\" ] }, { \"message\": \"Message2\", \"to\": [ \"98260XXXXX\", \"98261XXXXX\" ] } ] }"
};
$.ajax(settings).done(function (response) {
console.log(response);
})
}
解决方案
jQuery 没有被加载,因为您的 javascript 中有一个 HTML 标记。将此行移到 HTML 中,在上面调用 jQuery 的地方:
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>;
推荐阅读
- angular - Angular - 在不知道结构的情况下循环显示视图组件视图上的任何 json 数据
- flutter - 无法使用 Flutter 从 Firestore 检索文档
- python-3.x - NumPy - 创建具有递增幂的对角线的上三角矩阵
- python - pipenv 无法创建虚拟环境
- ios - 在纵向模式下输入 iPad 密码屏幕很奇怪
- html - select2 元素缩小宽度的原因可能是什么?
- redux - 如何创建一个辅助方法,该方法需要一个参数来过滤来自 redux 存储的数据?
- python - 在烧瓶中重定向后返回自定义http代码
- c++ - std::ranges::elements_view 用于自定义元组数据
- python - seaborn:x 刻度线图上消失