我有一个像 Facebook 这样的链接到女巫上的页面我没有完全控制权:我可以修改页面的<body>但不能修改<head>页面的...所以我尝试在一个新页面上设置点赞按钮的链接我有完全的控制权,在这个页面上设置 opengraph 元标记,并设置一个链接到原始页面的 og:url。
但最后 Facebook 试图从 og:url 中提取元数据并覆盖上一页的元标记......是否可以说我想从第一个获取的 url 而不是从 og:url 中抓取元数据?
metadata fetch canonical-link facebook-graph-api facebook-opengraph
我fetch在本机应用程序中使用。我试图读取响应,但是当我使用alert(response)我得到[object Object]。我尝试过其他模块,例如 xml2js、react-native-html-parser' 或 xmldom。
fetch(
/*
REQUEST CONFIGURATION
*/
}).then(response => {
console.log(response) // This is what returns [object Object]
})
Run Code Online (Sandbox Code Playgroud) 我有一个使用graphene-django实现的 graphql 服务器。我可以像这样使用 jquery 对其进行查询:
function allIngredients() {
return 'query{allProducts{edges{node{name}}}}'
}
var query = allIngredients();
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
$.post("/graphql", {query: query}, function(response) {
console.log(response);
})
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用 Fetch 进行此调用时,由于 CORS 问题,我收到了 403。我通过在调用之前添加 ajaxSetup... 在 jQuery 中解决了同样的问题。
这是使用 fetch 的调用:
fetch('/graphql', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({
csrfmiddlewaretoken: '{{ csrf_token }}',
query:`{allProducts{
edges{
node{
id
name
orderPrice
sellPrice
}
}
}`})
}
)
.then(function(response) {
if (response.status >= 400) …Run Code Online (Sandbox Code Playgroud) 在某些情况下,我认为这意味着“将数据从一个地方传输到另一个地方”。例如,使用 python 的 sqlalchemy 包,从 sql 数据库中“获取”数据以供 python 使用。
还有其他含义和上下文吗?
在我的 ReactJS 项目中,我使用 fetch 进行异步处理,并在获取数据后,
我想 setState 来改变我的本地状态。但我得到错误返回。
Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
取函数代码:
AddDeal(deal){
fetch('shops/1/deals',{
method: "POST",
body: JSON.stringify(deal),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).then(response => {
response.json().then(data =>{
this.setState({deals: data}); // and use this.props.dispatch I get `props` of undefined
})
})
}
Run Code Online (Sandbox Code Playgroud)
我看过另一个问题,比如我的React.js: loading JSON data with Fetch API and props from object array
那么我该如何解决呢?
我正在使用 Webpack 编译 Typescript (v2.4.2)。一切都编译正常,但是当我在 IE11 中运行我的代码时,我收到以下错误:'Promise' 未定义。
这是我的 tsconfig:
{
"compilerOptions": {
"outDir": "./wwwroot/js",
"sourceMap": true,
"allowJs": true,
"lib": [
"dom",
"es5",
"scripthost",
"es2015.iterable"
],
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"skipDefaultLibCheck": true,
"types": [ "es6-promise" ]
},
"include": [
"./Ts/**/*"
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的 webpack 配置:
const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
entry: {
main: "./Ts/main.ts"
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "wwwroot/js")
},
devtool: "source-map",
resolve: {
extensions: …Run Code Online (Sandbox Code Playgroud) 我是 ReactJS 的新手,但我现在正在尝试自学。当我尝试添加数据时遇到问题可能是数据库,在我的 RestAPI 和 MongoDB 中,在我的 Web 应用程序上使用 fetch 函数。当我单击我的按钮时,它运行以下代码:
SubmitClick(){
//console.log('load Get User page'); //debug only
fetch('http://localhost:4000/users/', {
method: 'POST',
headers: {
'Authorization': 'Basic YWRtaW46c3VwZXJzZWNyZXQ=',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'deadpool@gmail.com',
first_name: 'Wade',
last_name: 'Wilson',
personal_phone: '(11) 91111-2222',
password: 'wolv3Rine'
})
})
//this.props.history.push('/get'); //change page layout and URL
}
Run Code Online (Sandbox Code Playgroud)
我在浏览器上收到以下消息:
选项http://localhost:4000/users/ 401(未经授权)
加载http://localhost:4000/users/失败:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost:3000 '。响应的 HTTP 状态代码为 401。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
Uncaught (in promise) TypeError: Failed to fetch
我的 RestAPI 具有基本身份验证,但我不知道应该在标头中插入什么才能访问。我'Authorization': 'Basic YWRtaW46c3VwZXJzZWNyZXQ=', …
我有一个代码,undefined每当我尝试将结果提取到变量中时都会产生结果
var data;
fetch('./js/samplejson.json')
.then((res) => res.json())
.then(output => {
var data = output;
}
)
console.log(data);
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到结果
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
内部数据变量
我正在使用create-react-app和制作一个反应应用程序react-router-dom 4。我的问题是,当我加载默认“/”以外的 URL 时,相对路径会被添加到正在发出的请求中。
例如,如果我进入mysite.com/templatesurl 搜索栏,我的 fetch 请求会fetch("templates/item.json")请求 url:mysite.com/templates/templates/item.json但如果我从主页导航到/templates使用Linkreact-router-dom 中的 组件,则情况并非如此。
有什么方法可以避免在获取请求之前添加相对路径?
fetch reactjs react-router create-react-app react-router-dom
在它的npm 页面中whatwg-fetch说:
导入将自动填充 window.fetch 和相关 API:
Run Code Online (Sandbox Code Playgroud)import 'whatwg-fetch' window.fetch(...)
在同一部分的下面它说
要与 webpack 一起使用,请在应用程序入口点之前的入口配置选项中添加此包:
Run Code Online (Sandbox Code Playgroud)entry: ['whatwg-fetch', ...]
我用webpack.
我应该同时导入它并将其添加为条目,还是条目足够了?