我用以下代码创建了一个Chrome插件扩展:
$.ajax({
type: 'GET',
url: page_url
success: function(responseText){ ...在Wix corvid中,我尝试使用由于web服务器上的CORS策略而被阻塞的fetch请求。
Aynone会知道如何在Wix corvid中转换相当于ajax get请求的内容吗?
谢谢,
休斯
发布于 2020-02-20 04:47:02
如果您想使用GET,请执行以下操作。
//myfile.jsw
export async function myBackendFnc() {
const response = await fetch("https://api.website.com", {
method: 'GET',
});
const json = await response.json();
return json;
}如果外部web服务器阻止了此请求,那么您需要与外部服务器弄清楚如何将您的ip列入白名单。
您可以使用来自页面的GET,也可以使用使用后端文件的服务器端代码。
发布于 2020-03-20 07:03:37
要成功获取,请确保在代码顶部导入'wix- fetch‘API。
import {fetch} from 'wix-fetch';
// ...
export function getRequest() {
fetch("https://someapi.com/api/someendpoint", { "method": "get" })
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
})
.then(json => console.log(json.someKey))
.catch(err => console.log(err));
}有关更多信息,请查看API参考:https://www.wix.com/corvid/reference/wix-fetch.html
如果你愿意,你也可以使用use async await。
你可以在你的后端创建一个web模块,并从那里获取。你也可以选择从前端使用'wix-fetch‘。
https://stackoverflow.com/questions/60308569
复制相似问题