|
40 | 40 | } |
41 | 41 | }; |
42 | 42 |
|
| 43 | + var ajax = function(url, init) { |
| 44 | + init = Object.assign({credentials: 'same-origin'}, init); |
| 45 | + return fetch(url, init).then(function(response) { |
| 46 | + if (response.ok) { |
| 47 | + return response.text(); |
| 48 | + } else { |
| 49 | + var win = document.querySelector('#djDebugWindow'); |
| 50 | + win.innerHTML = '<div class="djDebugPanelTitle"><a class="djDebugClose djDebugBack" href=""></a><h3>'+response.status+': '+response.statusText+'</h3></div>'; |
| 51 | + $$.show(win); |
| 52 | + return Promise.reject(); |
| 53 | + } |
| 54 | + }); |
| 55 | + }; |
| 56 | + |
43 | 57 | var djdt = { |
44 | 58 | handleDragged: false, |
45 | 59 | events: { |
|
66 | 80 | var inner = current.querySelector('.djDebugPanelContent .djdt-scroll'), |
67 | 81 | store_id = djDebug.getAttribute('data-store-id'); |
68 | 82 | if (store_id && inner.children.length === 0) { |
69 | | - var ajax_data = { |
70 | | - data: { |
71 | | - store_id: store_id, |
72 | | - panel_id: this.className |
73 | | - }, |
74 | | - type: 'GET', |
75 | | - url: djDebug.getAttribute('data-render-panel-url') |
76 | | - }; |
77 | | - $.ajax(ajax_data).done(function(data){ |
| 83 | + var url = djDebug.getAttribute('data-render-panel-url'); |
| 84 | + url += '?' + new URLSearchParams({ |
| 85 | + store_id: store_id, |
| 86 | + panel_id: this.className |
| 87 | + }) |
| 88 | + ajax(url).then(function(body) { |
78 | 89 | inner.previousElementSibling.remove(); // Remove AJAX loader |
79 | 90 | inner.innerHTML = body; |
80 | 91 | $$.executeScripts(inner); |
81 | | - }).fail(function(xhr){ |
82 | | - var win = document.querySelector('#djDebugWindow'); |
83 | | - win.innerHTML = '<div class="djDebugPanelTitle"><a class="djDebugClose djDebugBack" href=""></a><h3>'+xhr.status+': '+xhr.statusText+'</h3></div>'; |
84 | | - $$.show(win); |
85 | 92 | }); |
86 | 93 | } |
87 | 94 | } |
|
109 | 116 | ajax_data.url = this.getAttribute('formaction'); |
110 | 117 |
|
111 | 118 | if (form) { |
112 | | - ajax_data.data = $(form).serialize(); |
| 119 | + ajax_data.body = new FormData(form); |
113 | 120 | ajax_data.method = form.getAttribute('method') || 'POST'; |
114 | 121 | } |
115 | 122 | } |
|
118 | 125 | ajax_data.url = this.getAttribute('href'); |
119 | 126 | } |
120 | 127 |
|
121 | | - $.ajax(ajax_data).done(function(data){ |
| 128 | + ajax(ajax_data.url, ajax_data).then(function(body) { |
122 | 129 | var win = djDebug.querySelector('#djDebugWindow'); |
123 | 130 | win.innerHTML = body; |
124 | 131 | $$.executeScripts(win); |
125 | | - }).fail(function(xhr){ |
126 | | - var win = document.querySelector('#djDebugWindow'); |
127 | | - win.innerHTML = '<div class="djDebugPanelTitle"><a class="djDebugClose djDebugBack" href=""></a><h3>'+xhr.status+': '+xhr.statusText+'</h3></div>'; |
128 | 132 | $$.show(win); |
129 | 133 | }); |
130 | 134 | }); |
|
0 commit comments