我正在使用 fetch 来获取数据。就像这样:
getClipMetadata = (url) => {
const endpoint = 'http://www.vimeo.com/api/oembed.json';
fetch(`${endpoint}?url=${encodeURIComponent(url)}`, {
method: 'get',
cache: 'no-cache',
mode: 'cors',
headers: new Headers({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
})
})
.then((response) => { return response.json();})
.then((res) => console.log("async response received", res))
.catch((err) => console.log("ajax error -> ", err))
}
Run Code Online (Sandbox Code Playgroud)
所以我得到的错误是这样的:
Response for preflight is invalid (redirect)
我认为从 Vimeo 的开发者页面来看它看起来很简单。
我究竟做错了什么?
请参阅以下过程。我没有关闭光标,它工作正常。我在这里错过了什么吗?是强制关闭游标还是Oracle自动关闭游标?
CREATE OR REPLACE PROCEDURE pr_cursor_test IS
CURSOR emp_cur IS SELECT empno, ename FROM emp;
emprec emp_cur%rowtype;
BEGIN
OPEN emp_cur;
LOOP
FETCH emp_cur INTO emprec;
EXIT WHEN
emp_cur%notfound;
--Do Something
dbms_output.put_line(emprec.ename);
END LOOP;
END;
Run Code Online (Sandbox Code Playgroud) 我希望我的提取请求有某种重试系统,如果它基于响应的 HTTP 代码(例如:不是 200)以某种方式失败。它看起来像这样:
fetch('someURLWithAJSONfile/file.json')
.then(function (res) {
console.log(res.status);
if (res.status !== 200) {
console.log("There was an error processing your fetch request. We are trying again.");
// Recursive call to same fetch request until succeeds
} else {
return res.json();
}
}).then(function (json) {
data = json;
}).catch(function (err) {
console.log(`There was a problem with the fetch operation: ${err.message}`);
});
Run Code Online (Sandbox Code Playgroud)
有没有办法将获取请求放入自定义 Promise 中,并使其在检查其 http 响应状态后调用自身?
我正在尝试找到一种在我的 React 应用程序中显示图像的方法。我需要的图像需要一个不记名令牌,换句话说,当我访问此图像时,我需要传递一个带有不记名令牌的标头。我正在从 react-native 转向 react,所以在 react-native 中,我可以直接在 Image 组件中给出标题,但似乎我无法在 img 标记中传递标题,即 html 标记。所以我的问题是如何显示需要不记名令牌才能在反应中访问它的图像。
所以我正在尝试使用文档中描述的新功能。
但是我最终得到了这个错误:
属性或方法“$fetchState”未在实例上定义,但在渲染期间被引用。
尽管我的组件清楚地定义了 fetch() 方法并且我设法从中得到了一些东西。
<template>
<div v-if="$fetchState">
<p v-if="$fetchState.pending">Fetching posts...</p>
<p v-else-if="$fetchState.error">Error while fetching posts</p>
<div v-else>
<div v-if="content.content1" v-html="content.content1" />
<div v-if="content.content2" v-html="content.content2" />
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
async fetch({ store, error }) {
try {
await store.dispatch('home/fetchContent')
} catch (e) {
error({
statusCode: 503,
message: 'Unable to fetch'
})
}
},
computed: mapState({
content: (state) => state.home.content
})
}
</script>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过?
我有一个我的博览会应用程序正在查询的节点后端。node-express-mongo 后端工作得非常完美,我可以使用 Postman 的 GET 请求进行验证,但我的应用程序中出现未处理的承诺拒绝网络失败错误
完全错误:
[Unhandled promise rejection: TypeError: Network request failed]
- node_modules/whatwg-fetch/dist/fetch.umd.js:473:29 in xhr.onerror
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:574:29 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
api.js
export const fetchMeetups = () =>
fetch('http://localhost:3000/api/meetups')
.then(res => res.json());
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import * as React from 'react';
import { Platform, StyleSheet, Text, View, …Run Code Online (Sandbox Code Playgroud) 在我的Laravel应用程序中,我使用Fetch API滚动加载数据。下面是我JS在刀片文件中的代码
let route = '{{ route("load") }}' + '?q=' + encodeURI('{{ $para }}');
fetch(route)
.then(response => {
if(!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
})
Run Code Online (Sandbox Code Playgroud)
在我的控制器中
public function loadData( Request $request )
{
if( $request->ajax() ) {
return $request->query('q');
}
return 'Not Ajax!';
}
Run Code Online (Sandbox Code Playgroud)
它总是返回“不是 Ajax!”;
我不确定为什么会这样。这不是一个问题,与其他图书馆喜欢jQuery或Axios
我想获取这个网址的数据https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt#L2
我正在尝试使用 fetch api 来获取数据,但我收到了 cors 错误
这是我想要做的
async function showmodal1() {
console.log("hello")
const data = await
fetch('https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt');
console.log(data)
}
showmodal1();
Run Code Online (Sandbox Code Playgroud)
有什么方法可以获取 github txt 文件的数据我尝试通过互联网找到它,但我找不到任何东西提前谢谢您的帮助
编辑:
Access to fetch at 'https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. changelog.html:361
GET https://github.com/ProjectSakura/OTA/blob/10/changelog/changelog_beryllium.txt net::ERR_FAILED
showmodal1 @ changelog.html:361
(anonymous) @ changelog.html:365 …Run Code Online (Sandbox Code Playgroud) 我正在使用 Fetch 将 JSON 数据输出到 Google 表格
Fetch 函数未将 JSON 中的所有数据输出到工作表
你可以看到,列N通过R没有被添加到表
这是我的 Fetch 功能
function fetchData() {
// Set Fetch Variables
var url = "https://sum-app.net/projects/13435720200118544/download_data/combined_json"
var response = UrlFetchApp.fetch(url);
var responseText = response.getContentText();
var responseJson = JSON.parse(responseText);
var connectionKeys = Object.keys(responseJson.connections[0]);
var data = responseJson.connections.map(e => connectionKeys.map(f => {
return e[f] instanceof Array ? e[f].join("|") : e[f];
}));
data.unshift(connectionKeys);
data = data.map(x => x.map(y => typeof y === 'undefined' …Run Code Online (Sandbox Code Playgroud) 据我所知,useEffect 钩子最后作为 sideEffect 运行。我正在尝试控制台日志 data.main.temp。我可以理解它还不知道那是什么,因为它正在从后面运行的 useEffect 钩子中的 api 获取数据。
在 api 调用后,我如何能够访问或控制台日志 data.main.temp?(我觉得 setTimout 是作弊方式?)
import React, { useState, useEffect } from "react";
import Button from "../UI/Button";
import styles from "./Weather.module.css";
import moment from "moment";
import Card from "../UI/Card";
export default function Weather() {
//State Management//
const [lat, setLat] = useState([]);
const [long, setLong] = useState([]);
const [data, setData] = useState([]);
//openWeather API key
const key = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
useEffect(() => {
const fetchData = async () => {
//get coordinates// …Run Code Online (Sandbox Code Playgroud) fetch ×10
javascript ×5
cors ×2
react-native ×2
reactjs ×2
ajax ×1
android ×1
api ×1
async-await ×1
cursor ×1
ecmascript-6 ×1
expo ×1
express ×1
html ×1
laravel ×1
node.js ×1
nuxt.js ×1
oracle ×1
php ×1
promise ×1
use-effect ×1
use-state ×1
vimeo ×1
vue.js ×1