jquery - 我可以在本机反应中使用 jquery 吗?
问题描述
我可以在反应式本机应用程序中使用 ajax 吗?如果不是,我如何使用 fetch 执行类似的命令?
$.ajax({
type: "GET",
url: "https://test.com/api",
contentType: "application/json",
crossDomain: true,
dataType: "text",
xhrFields: {
withCredentials: true
},
username: 'user',
password: 'pass',
failure: function(errMsg) {
alert(errMsg);
}
}).done(function(data) {
console.log(data)
});
解决方案
这里有一个用于获取数据的示例获取 API 等等
return fetch(
"URL",
{
headers: {
"Accept": "application/json",
"Authorization": "Basic " + btoa('username:password'),
"Content-Type": "application/json",
"User-Agent":
"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25",
"x-correlation-id": "asfsef4243sdf",
"x-channel": "android"
},
method: "GET", // *GET, POST, PUT, DELETE, etc.
}
)
.then(response => {
console.log("got json" + response);
response.json();
})
.then(responseJson => {
console.log("Hey = "+responseJson);
})
.catch(error => {
console.error(error);
});
推荐阅读
- c# - 使用 PKCE 登录 Discord OAuth 的过程
- android - 在firebase中实现电话和电子邮件身份验证的最佳方法是一次性使用?
- node.js - 在 node.js 中,我无法将变量传递给类的成员函数
- java - 有没有办法找到数组的特定排列?
- assembly - 汇编 - 如何使用压入堆栈的变量
- c# - 如何修复错误 - 操作数类型冲突:日期与 int 不兼容
- python - 使用带有 REST api 的 Python/PyMongo 更新 MongoDB 时遇到问题
- python - 二叉树不显示节点存在 Python
- css - 返回几个元素的父选择器
- php - 如何在一个php中显示两个数据表?但它只出来一个表记录