|
@@ -77,23 +77,34 @@
|
|
|
log(`Making request: ${action}`, 'info');
|
|
log(`Making request: ${action}`, 'info');
|
|
|
|
|
|
|
|
return fetch(`ajax_import_test.php?${params}`)
|
|
return fetch(`ajax_import_test.php?${params}`)
|
|
|
- .then(response => response.json())
|
|
|
|
|
- .then(data => {
|
|
|
|
|
- if (data.success) {
|
|
|
|
|
- log(`✓ ${data.message} (${data.step})`, 'success');
|
|
|
|
|
- if (data.stats) {
|
|
|
|
|
- log(`Stats: ${JSON.stringify(data.stats)}`, 'info');
|
|
|
|
|
- }
|
|
|
|
|
- if (data.result) {
|
|
|
|
|
- log(`Result: ${JSON.stringify(data.result)}`, 'info');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ .then(response => {
|
|
|
|
|
+ const contentType = response.headers.get('content-type');
|
|
|
|
|
+ if (contentType && contentType.includes('application/json')) {
|
|
|
|
|
+ return response.json().then(data => {
|
|
|
|
|
+ if (data.success) {
|
|
|
|
|
+ log(`✓ ${data.message} (${data.step})`, 'success');
|
|
|
|
|
+ if (data.stats) {
|
|
|
|
|
+ log(`Stats: ${JSON.stringify(data.stats)}`, 'info');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data.result) {
|
|
|
|
|
+ log(`Result: ${JSON.stringify(data.result)}`, 'info');
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log(`✗ ${data.message} (${data.step})`, 'error');
|
|
|
|
|
+ if (data.error) {
|
|
|
|
|
+ log(`Error details: ${data.error.file}:${data.error.line}`, 'error');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return data;
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
- log(`✗ ${data.message} (${data.step})`, 'error');
|
|
|
|
|
- if (data.error) {
|
|
|
|
|
- log(`Error details: ${data.error.file}:${data.error.line}`, 'error');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Handle HTML response (likely PHP error)
|
|
|
|
|
+ return response.text().then(html => {
|
|
|
|
|
+ log(`⚠ Server returned HTML instead of JSON:`, 'error');
|
|
|
|
|
+ log(`First 500 chars: ${html.substring(0, 500)}`, 'error');
|
|
|
|
|
+ throw new Error('Server returned HTML instead of JSON');
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- return data;
|
|
|
|
|
})
|
|
})
|
|
|
.catch(error => {
|
|
.catch(error => {
|
|
|
log(`Network error: ${error.message}`, 'error');
|
|
log(`Network error: ${error.message}`, 'error');
|