[WebProfilerBundle] Propose to open debug toolbar request in an error occured.

This is very useful when creating data collectors and an error occurs
when redering the toolbar via XHR.
This commit is contained in:
alexandresalome 2011-09-17 14:16:35 +02:00
parent 61487cb6f7
commit fe76d746ec

View File

@ -2,18 +2,21 @@
<script type="text/javascript">/*<![CDATA[*/
(function () {
var wdt, xhr;
var url = '{{ path("_wdt", { "token": token }) }}';
wdt = document.getElementById('sfwdt{{ token }}');
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('GET', '{{ path("_wdt", { "token": token }) }}', true);
xhr.open('GET', url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = function(state) {
if (4 === xhr.readyState && 200 === xhr.status && -1 !== xhr.responseText.indexOf('sf-toolbarreset')) {
wdt.innerHTML = xhr.responseText;
wdt.style.display = 'block';
} else if (4 === xhr.readyState && xhr.status != 200) {
confirm('An error occured while loading the debug toolbar ('+xhr.status+': '+xhr.statusText.') .\n\nDo you want to open the page ?') && (window.location = url);
}
};
xhr.send('');