0

我正在尝试不带导轨的涡轮驱动器。

它似乎适用于表单但不适用于链接..即使表单设置为GET.

为了尽量减少它,我使用了 bash 和 cgi,但是我在使用另一个 Web 框架时看到了同样的东西。

$ mkdir example
$ cd example
$ cat > index.html
<meta http-equiv="Refresh" content="0; url='/cgi-bin/index.sh'" />

$ mkdir cgi-bin
$ cat > cgi-bin/index.sh
#! /usr/bin/env bash

set -e

echo Content-Type: text/html
echo
sed "s/NEW/$RANDOM/g" << EOF
<html>
  <head>
    <title>DEMO</title>
    <script src="/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js"></script>
  </head>
  <body>
    <h1>DEMO</h1>
    <h2>$QUERY_STRING</h2>
    <a href="?val=NEW">NEW</a>
    <form action="?">
        <input type="hidden" name="val" value="NEW" />
        <input type="submit" />
    </form>
  </body>
</html>
EOF

$ chmod +x cgi-bin/index.sh
$ npm install --save @hotwired/turbo@7.0.1
$ python3 -m http.server --cgi # or whichever server

然后当我去http://localhost:8000我得到这个:

带有链接和提交按钮的示例网页

链接和提交按钮都加载链接中显示的随机数,并准备一个新的随机数进行加载。

显示来自表单或链接的查询字符串的网页

不同之处在于链接会重新加载整个页面,就好像不包括涡轮增压器一样,并且会获取表单。

网络选项卡显示来自链接的完整页面加载和来自表单的 ajax

我该怎么做才能使它也成为 ajax 链接?我是否忽略了链接中需要的属性或其他内容?

4

1 回答 1

0

地址中带有 html 扩展名的网页

单步执行代码我发现了这种情况:

function isHTML(url) {
    return !!getExtension(url).match(/^(?:|\.(?:htm|html|xhtml))$/);
}

所以我重命名index.shindex.html并且它起作用了!我想它可能也可以在没有文件名的情况下使用。

该限制仅适用于链接,不适用于表单。

于 2021-10-07T19:29:50.970 回答