相关疑难解决方法(0)

xmlhttprequest用于本地文件

我有一个文件的路径,我想发送到服务器的休息Web服务.我正在使用xmlhttprequest对象.这篇文章如下:

var url = "http://localhost:8080/RestWSGS/jersey/gridsense";
 var boundary = "--------------" + (new Date).getTime();
  xmlHttp.open('POST', url, true);
  xmlHttp.onreadystatechange = function ()
  {
      if (this.readyState != 4)
        return;

      var result =this.responseText;
    document.write(result);
    };
  xmlHttp.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);

var  part ="";
 part += 'Content-Disposition: form-data; ';
  part += 'name="' + document.getElementById("filename").name + '" ; ';
  //alert(document.getElementById("filename").value);
  part += 'filename="'+ document.getElementById("filename").value +  '";\r\n';

  part += "Content-Type: application/xml";
  part += "\r\n\r\n"; // marks end of the headers part
  part += 'filename="'+ document.getElementById("filename").value +  '";\r\n';
  part+= …
Run Code Online (Sandbox Code Playgroud)

xmlhttprequest

25
推荐指数
2
解决办法
8万
查看次数

Fetch API无法加载file:/// C:/ Users/Jack/Desktop/Books_H/book-site/public/api/books.对于CORS请求,URL方案必须是"http"或"https"

刚开始在我的学校学习节点js.他们给了我们这个半完成的任务,我需要让next和prev按钮工作.但是,当我运行index.html时,我在控制台中出现了一些错误.错误是:

"Fetch API无法加载文件:/// C:/ Users/Jack/Desktop/Books_H/book-site/public/api/books.对于CORS请求,URL方案必须为"http"或"https"."

另一个是:

"未捕获(承诺)TypeError:无法获取HTMLDocument.document.addEventListener".

我甚至不知道如何开始解决这个问题.有帮助吗?

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1000, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello</title>
</head>
<body>
    Hello from the other side! <b>Total: <span id="total"></span></b><br/>
    <button id="author">Sort by author</button>
    <button id="title">Sort by title</button>
    <table id="books" border="1">
        <tr>
            <th>
                Author
            </th>
            <th>
                Book Title
            </th>
        </tr>

    </table>
    <script src="index.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

java脚本文件

    document.addEventListener("DOMContentLoaded", () => {
    processResponse(fetch("api/books"));

    document.getElementById("author").addEventListener("click", () =>{
        processResponse(fetch("api/books?sortby=author"))
    });

    document.getElementById("title").addEventListener("click", () =>{
        processResponse(fetch("api/books?sortby=title"))
    });

});

function processResponse(response) {
    let table …
Run Code Online (Sandbox Code Playgroud)

html javascript node.js

9
推荐指数
1
解决办法
2万
查看次数

反应中的 Tensorflow Automl 模型

我正在尝试将 tensorflow 模型从其原始 html 移动到 react 应用程序(使用 create-react-app 构建)。

我的 App.js 看起来像这样:

import logo from './logo.svg';
import * as tf from "@tensorflow/tfjs";
// import { loadImageclassification } from "@tensorflow/tfjs";
import './App.css';
import * as automl from "@tensorflow/tfjs-automl";
import * as modelJSON from './model.json';

function App() {

var loadFile = function(event) {
    var image = document.getElementById('output');
    image.src = URL.createObjectURL(event.target.files[0]);
  run();
};

async function run() {
  console.log(modelJSON);
        // const model = await tf.loadImageclassification('model.json');
        const model = await automl.loadImageClassification(modelJSON);
        const image = document.getElementById('output'); …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs tensorflow automl tensorflow.js

8
推荐指数
1
解决办法
440
查看次数

Chrome-Fetch API无法加载文件。解决方法

我有以下两个文件:

index.html

<html>
<head>
<meta charset="utf-8" />
<title>Web Page</title>
<style type="text/css">
.text {
    display: inline-block;
    font-family: tahoma;
    font-size: 14px;
    max-width: 400px;
    background-color: #ddedff;
    padding: 10px;
    text-align: justify;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    get_data('info.txt');
});
function get_data(file) {
    var request = new Request(file);
    fetch(request).then(function(response) {
        return response.text().then(function(text) {
            $('.text').html(text);
        });
    });
}
</script>
</head>
<body>
    <div class="text"></div>
</body>
<html>
Run Code Online (Sandbox Code Playgroud)

info.txt

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's …
Run Code Online (Sandbox Code Playgroud)

javascript firefox google-chrome fetch-api

7
推荐指数
1
解决办法
7991
查看次数

在JavaScript中从本地文件系统加载Tensorflow js模型

我已经将keras模型转换为tensorflow json格式,并将其保存在本地计算机中。我正在尝试使用以下命令在javascript代码中加载该json模型

model = await tf.loadModel('web_model')
Run Code Online (Sandbox Code Playgroud)

但是没有加载模型。有没有办法从本地文件系统加载tensorflow json模型?

javascript tensorflow tensorflow.js

3
推荐指数
3
解决办法
4123
查看次数