I have the following simple PHP page:
<?php
echo 'done';
When I send a Javascript fetch
request to that URL, I can inspect the response in the browser’s dev tools and see that it returns the string ‘done’.
Here is the request:
const response = await fetch(url, {
credentials: 'include'
});
On the other hand, if I start a session, the response is blank:
<?php
session_start();
echo 'done';
In both cases, the request headers are exactly the same, the response headers are exactly the same and the HTTP code is 200. It also works correctly if I manually go to that URL in the browser. It only fails specifically with fetch
requests.
Note, I have display_errors
and display_startup_errors
set to On
and nothing is outputted to the browser and nothing is logged in the log file either.
2
Answers
This behavior is because of a bug with Chromium that the devs have decided they "WontFix" and have stopped answering comments.
In order to get it to work, you need to manually read
response.text()
orresponse.json()
:Once you do that, the response body will show up in your dev tools. If not, it will appear as if the response was empty, even if it wasn't.
You can use
async
withAwait
You can change the
.json()
totext()