有一个从服务器返回数据的ajax请求并且有效:
$('#add').on('click', function() {
$.ajax({
type: "POST",
url: '/add-category',
success: onAddSuccess,
});
function onAddSuccess(data) {
response = data;
}
}
我正在尝试用fetch请求重写它:
$('#add').on('click', function() {
let response = fetch('/add-category');
let result = response;
}
并得到
Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Response
body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://localhost/add-category"
__proto__: Response
但是没有数据。请告知如何获得它们?
Yii2,Windows 10
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch