Symfony News

New in Symfony 4.1: Ajax improvements

A simpler way to test Ajax requests

Contributed by
Hamza Amrouche
in #26381.

The BrowserKit component used in Symfony functional tests provides lots of utilities to simulate the behavior of a web browser. In Symfony 4.1 we've added a new utility to make Ajax requests simpler: xmlHttpRequest().

This method works the same as the current request() method and accepts the same arguments, but it adds the required HTTP_X_REQUESTED_WITH header automatically so you don't have to do that yourself:

1
2
3
4
5
6
7
// Before
$crawler = $client->request('GET', '/some/path', [], [], [
    'HTTP_X-Requested-With' => 'XMLHttpRequest',
]);

// After
$crawler = $client->xmlHttpRequest('GET', '/some/path');

Improved the Ajax panel in the debug toolbar

Contributed by
Gabriel Ostrolucký, and Javier Eguiluz in #26665 and #26668.

The first minor but noticeable change is that the link to the Ajax request profile has been moved to the first column of the table, so it's easier to click on it.

In addition, when the Ajax request results in an exception (HTTP status of 400 or higher) the profiler link points to the exception profiler panel instead of the default request/response panel:

In any case, the biggest new feature of the Ajax panel is that requests now display their duration in real-time, so you always know which requests are still pending to finish:


Be trained by Symfony experts - 2018-04-23 Lyon - 2018-04-23 Lyon - 2018-04-25 Clichy


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Resources

Find us on Twitter

Find us on Facebook