Thomas Potaire Thomas Potaire - 1 year ago 48
jQuery Question

How to update the web profiler toolbar to show data about an ajax request

I am currently building an app that fully supports ajax page load. After an initial page load, navigating through the website only loads the content and not the header or the menu.

The whole app is working great but I would like to refresh the web profiler tool bar to show the last ajax request information.

I got the xdebug token from the response header and I am trying to extend the javascript part to replace the current content of toolbar but I haven't been successful yet.

How can I accomplish this? Is there anything specific I should be aware of?

Answer Source

I ultimately "reverse-engineered" the load method of the object Sfjs and turns out it's working pretty nicely.

Here is the solution

// Query the proper URL
$.get('/my-url', function (data, status, xhr) {
    // Get the xdebugToken from response headers
    var xdebugToken = xhr.getResponseHeader('X-Debug-Token');

    // If the Sfjs object exists
    if (typeof Sfjs !== "undefined") {

        // Grab the toolbar element
        var currentElement = $('.sf-toolbar')[0];

        // Load the data of the given xdebug token into the current toolbar wrapper
        Sfjs.load(, '/_wdt/'+ xdebugToken);