首页 > 解决方案 > 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);
})
}

标签: javascriptjquerygoogle-apps-scriptgoogle-sheets-api

解决方案


jQuery 没有被加载,因为您的 javascript 中有一个 HTML 标记。将此行移到 HTML 中,在上面调用 jQuery 的地方:

  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>;

推荐阅读