我可以在反应式本机应用程序中使用Ajax吗?如果没有,如何使用访存执行类似的命令?
$.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)
});
答案 0 :(得分:0)
这里有一个样本获取API,用于获取数据和更多here
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);
});