0
votes

When fetching data, sometimes, my app will return the html for the debug toolbar. What makes this quite bizarre, is that it does NOT happen every time. I had to refresh the page 7 times for it to happen. In some cases it does it all the time.

When I turn off the profiler, there is no problem fetching the data.

I tried to switch to jQuery ajax, but I got the same type of results.

I am using the symfony server, symfony 4.2, php7.2, webpack encore, React js.

If I use postman to connect to the api, then I have no failures. Only from the web page doing ajax.

I stripped down to putting the js code directly into the twig file to bypass Webpack.

I am looking for suggestions on how to troubleshoot this.

Thank you very much.

UPDATE:

I checked the logs and it looks like the matched route is wrong.

Jul 17 15:44:48 SERVER GET  (200) /api/map-point/list/quick/26.190096/-80.365865
Jul 17 15:44:48 REQUES Matched route "_wdt". method="GET" request_uri="https://127.0.0.1:8000/_wdt/3de748
1
More strange... If the fetch function is executed twice, both calls are successful and retrieve the data. If I remove 1, then problems start again.ScottGutman

1 Answers

0
votes

There may be multiple causes for this behavior.

My first guess is this could be caused by a missing/incorrect Accept header. Without the header symfony might think you're requesting an html-page and add the toolbar's html to the response.

Open the network panel of your browser and check if the Accept: application/json and Content-Type: application/json headers are present in the (XHR-)Request you're sending to your application and in the response.

Further you could try to configure the profiler to collect data only for master requests or not. Try both configurations.

framework:
  profiler:
    only_master_requests: true # (default: false)

(Framework Configuration - Profiler - #only-master-requests)

Make sure to clear your cache afterwards.