0

Today I've discovered a strange thing. When I create an XHR request in Chrome to the REST API, it returns JSON data.

However, the same request in Firefox returns XML data. If I open the URL directly in Chrome, it's XML as well.

I couldn't find anything about this in the REST documentation of Magento 2. So how can I set my XHR request the return always JSON?

2

Aha, it turns out I have to send an additional header in my XHR request in order to force JSON:

xhr.setRequestHeader("Accept", "*/*");
xhr.setRequestHeader("Content-type", "application/json");

Hopefully this saves somebody else a couple of hours...

0

Just use storage.get() after requiring mage/storage which will set the appropriate headers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.