ajax_import_interface.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>AJAX WordPress Import Test</title>
  5. <style>
  6. body { font-family: Arial, sans-serif; margin: 20px; }
  7. .container { max-width: 800px; margin: 0 auto; }
  8. .form-group { margin-bottom: 15px; }
  9. label { display: block; margin-bottom: 5px; font-weight: bold; }
  10. input, button { padding: 8px; margin-bottom: 10px; }
  11. button { background: #007cba; color: white; border: none; cursor: pointer; margin-right: 10px; }
  12. button:hover { background: #005a87; }
  13. .log { background: #f5f5f5; border: 1px solid #ddd; padding: 10px; margin-top: 20px; height: 300px; overflow-y: auto; font-family: monospace; font-size: 12px; }
  14. .success { color: green; }
  15. .error { color: red; }
  16. .info { color: blue; }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="container">
  21. <h1>AJAX WordPress Import Test</h1>
  22. <p>This bypasses form submission issues by using AJAX requests.</p>
  23. <div class="form-group">
  24. <label>Host:</label>
  25. <input type="text" id="wp_host" value="10.15.10.8">
  26. </div>
  27. <div class="form-group">
  28. <label>Database:</label>
  29. <input type="text" id="wp_database" value="valtsu_valtsu">
  30. </div>
  31. <div class="form-group">
  32. <label>Username:</label>
  33. <input type="text" id="wp_username" value="">
  34. </div>
  35. <div class="form-group">
  36. <label>Password:</label>
  37. <input type="password" id="wp_password" value="">
  38. </div>
  39. <div class="form-group">
  40. <button onclick="testConnection()">Test Connection</button>
  41. <button onclick="importCategories()">Import Categories</button>
  42. <button onclick="importUsers()">Import Users</button>
  43. <button onclick="importPosts()">Import Posts</button>
  44. <button onclick="clearLog()">Clear Log</button>
  45. </div>
  46. <div id="log" class="log"></div>
  47. </div>
  48. <script>
  49. function log(message, type = 'info') {
  50. const logDiv = document.getElementById('log');
  51. const timestamp = new Date().toLocaleTimeString();
  52. const className = type === 'error' ? 'error' : type === 'success' ? 'success' : 'info';
  53. logDiv.innerHTML += `<div class="${className}">[${timestamp}] ${message}</div>`;
  54. logDiv.scrollTop = logDiv.scrollHeight;
  55. }
  56. function getConfig() {
  57. return {
  58. wp_host: document.getElementById('wp_host').value,
  59. wp_database: document.getElementById('wp_database').value,
  60. wp_username: document.getElementById('wp_username').value,
  61. wp_password: document.getElementById('wp_password').value
  62. };
  63. }
  64. function makeRequest(action) {
  65. const config = getConfig();
  66. const params = new URLSearchParams({...config, action});
  67. log(`Making request: ${action}`, 'info');
  68. return fetch(`ajax_import_test.php?${params}`)
  69. .then(response => {
  70. const contentType = response.headers.get('content-type');
  71. if (contentType && contentType.includes('application/json')) {
  72. return response.json().then(data => {
  73. if (data.success) {
  74. log(`✓ ${data.message} (${data.step})`, 'success');
  75. if (data.stats) {
  76. log(`Stats: ${JSON.stringify(data.stats)}`, 'info');
  77. }
  78. if (data.result) {
  79. log(`Result: ${JSON.stringify(data.result)}`, 'info');
  80. }
  81. } else {
  82. log(`✗ ${data.message} (${data.step})`, 'error');
  83. if (data.error) {
  84. log(`Error details: ${data.error.file}:${data.error.line}`, 'error');
  85. }
  86. }
  87. return data;
  88. });
  89. } else {
  90. // Handle HTML response (likely PHP error)
  91. return response.text().then(html => {
  92. log(`⚠ Server returned HTML instead of JSON:`, 'error');
  93. log(`First 500 chars: ${html.substring(0, 500)}`, 'error');
  94. throw new Error('Server returned HTML instead of JSON');
  95. });
  96. }
  97. })
  98. .catch(error => {
  99. log(`Network error: ${error.message}`, 'error');
  100. throw error;
  101. });
  102. }
  103. function testConnection() {
  104. makeRequest('test_connection');
  105. }
  106. function importCategories() {
  107. makeRequest('import_categories');
  108. }
  109. function importUsers() {
  110. makeRequest('import_users');
  111. }
  112. function importPosts() {
  113. makeRequest('import_posts');
  114. }
  115. function clearLog() {
  116. document.getElementById('log').innerHTML = '';
  117. }
  118. // Auto-focus username field
  119. document.addEventListener('DOMContentLoaded', function() {
  120. document.getElementById('wp_username').focus();
  121. });
  122. </script>
  123. </body>
  124. </html>