D8: How to perform ajax call in javascript
Instead of specifying an incorrect datatype in the client call, you fix your route and specify that you return json. Use the _format route key as explained in the route documentation