magespecialist/mage-chrome-toolbar

How to handle ajax actions?

Koc opened this issue · 8 comments

Koc commented

For example we have some ajax action which return json/xml. How it possible to profile it?

We are investigating on it to find a good way to debug it. Do you have any suggestion about that?

Koc commented

Maybe using Symfony's approach: write serialized data + csv index with possibility show info about last N requests. Plus overwrite xmlhttprequest http://symfony.com/blog/new-in-symfony-2-6-ajax-requests-in-the-web-debug-toolbar

Could be an option. Thank you for your suggestion. We are also investigating in using payloads inside the response headers.

Koc commented

Please do not make response headers too big, it may cause hard to debug errors on webserver/browser side. See Seldaek/monolog#172

That was exactly our concern! This is why we stopped it for a while, but your suggestion could be a better option.

In https://github.com/maximebf/php-debugbar we use different approaches:

  • For regular requests, render the data in json on the page itself
  • For ajax requests, send a request ID in the headers. This ID is used to make an ajax request to the API to get the data (to prevent too large headers)
  • For redirects (post actions), store the data in the session.

It then provides a dropdown to switch between requests. Eg. a save action will have 2 items, the POST request and the redirected page. So you can always see what happened on the POST (which is mostly more interesting). And ajax requests will trigger a new item in the dropdown.

@barryvdh , seems a good approach.