-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于fetch的使用 #10
Comments
$.ajax({
url: 'https://hacker-news.firebaseio.com/v0/jobstories.json',
method: 'GET'
}).done(data => {
/** 备注这里的url只是测试用的,这个是之前hackernews的api,
* 这里只是确保接口是通的,至于数据还是自己mock
*/
let weight = Math.floor(200 + Math.random()*50);
dispatch(actions.donePickApple(weight));
}).fail(xhr => {
dispatch(actions.failPickApple(xhr.responseText));
})
fetch('https://hacker-news.firebaseio.com/v0/jobstories.json')
.then(response => {
console.log(response.status);
console.log(response);
console.log(response.json())
}).catch(e => {
console.log('something wrong');
});
/** 错误返回的responese */
{
body: ReadableStream,
bodyUsed:true,
headers: Headers,
ok: false,
status: 401,
statusText: "Unauthorized",
type: "cors",
url: "https://hacker-news.firebaseio.com/v0/jobstories123.json'"
...
}
/** 正确返回的responese */
{
body: ReadableStream,
bodyUsed:true,
headers: Headers,
ok: true,
status: 200,
statusText: "OK",
type: "cors",
url: "https://hacker-news.firebaseio.com/v0/jobstories.json'"
...
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题:
The text was updated successfully, but these errors were encountered: