我可以在react native中使用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);
});

最新更新