【问题标题】:Javascript file not found / ERR_ABORTED未找到 Javascript 文件 / ERR_ABORTED
【发布时间】:2017-12-23 21:57:27
【问题描述】:

我正在创建一个与 Trello API 交互的 javascript 文件,但是当我运行该文件时,它在 Chrome 开发工具中是这样说的:

GET http://localhost:8080/js/trello.js net::ERR_ABORTED

GET http://localhost:8080/js/trello.js 404 (Not Found)

trello.js 肯定在 /js 中,我只尝试过 /trello.js 但似乎没有任何效果。有人可以帮助新手吗?我正在使用带有 Python 和 webapp2 的 Google App Engine。

HTML

<html>
 <head>
  <title>Admin Page</title>
 </head>
 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <script src="https://api.trello.com/1/client.js?key={APIKey}"></script>
 <script type="text/javascript" src="js/trello.js"></script>
 <body>
  {% if admin %}
  <p>All Work Requests</p>
  <a href="{{ logout_url }}">log out</a><br>
  <a href="trello.js">Trello test</a>
{% for result in results %}
  <table>
   <tr>
    <th><b>{{ result.email }}</th>
    <th><b> {{ result.date }}</th>
    <th><b> {{ result.title }}</th>
    <th><b> {{ result.key.id() }}</th>
    <th><a href="/delete/{{ result.key.id() }}">Delete</a></th>
    <th><a href="/assign/{{ result.key.id() }}">Assign</a></th>
   </tr>
  </table>
{% endfor %}
<p>{{ result }}</p>
  {% else %}
  <p>Welcome please <a href="{{ login_url }}">login...</a>
    <p>Not admin</p>
  {% endif %}
 </body>
</html>

trello.js

var authenticationSuccess = function() {
  console.log('Successful authentication');
};

var authenticationFailure = function() {
  console.log('Failed authentication');
};

window.Trello.authorize({
  type: 'popup',
  name: 'Getting Started Application',
  scope: {
    read: 'true',
    write: 'true' },
  expiration: 'never',
  success: authenticationSuccess,
  error: authenticationFailure
});

var myList = 'removed';

var creationSuccess = function (data) {
  console.log('Card created successfully.');
  console.log(JSON.stringify(data, null, 2));
};

var newCard = {
  name: 'New Test Card',
  desc: 'This is the description of our new card.',
  // Place this card at the top of our list
  idList: myList,
  pos: 'top'
};

window.Trello.post('/cards/', newCard, creationSuccess);

//window.Trello.put('/cards/[ID]', {name: 'New Test Card'});

【问题讨论】:

  • 快速猜测:Trello.jstrello.js?
  • 不,很遗憾,我将编辑我的帖子说 trello.js
  • 好吧本来很容易:D
  • Idk Google 应用引擎,但我认为有一些公用文件夹?您的 js 文件夹应该在其中。如果没有公用文件夹或者它已经存在,我担心我们需要等待专家。
  • 你可能是对的,我会读一读。谢谢。

标签: javascript python google-app-engine


【解决方案1】:

您需要app.yaml 中的静态 url 处理程序。试试:

- url: /static
  static_dir: foldername/static

如果静态目录位于文件夹内,则需要foldername,其中文件夹与app.yaml 处于同一级别。如果staticapp.yaml 处于同一级别,则为

- url: /static
  static_dir: static

然后,将您的/js 目录放入静态目录中,并将路径更改为:

<script type="text/javascript" src="static/js/trello.js"></script>

或者,保持路径不变,并在app.yaml 中创建一个直接指向它的处理程序:

- url: /js
  static_dir: somefolder/static/js
  # or static_dir: static/js if inside static dir which is at same level as app.yaml
  # or static_dir: js  if js dir at same level as app.yaml

我更喜欢将所有静态文件放在static 目录中。像static/jsstatic/imgstatic/fonts 等。顶级解决方案使用单个static url 处理程序处理所有问题

【讨论】:

    猜你喜欢
    • 2020-12-30
    • 2020-11-03
    • 2023-03-21
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 2021-06-11
    • 2020-02-16
    相关资源
    最近更新 更多