| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>AJAX WordPress Import Test</title>
- <style>
- body { font-family: Arial, sans-serif; margin: 20px; }
- .container { max-width: 800px; margin: 0 auto; }
- .form-group { margin-bottom: 15px; }
- label { display: block; margin-bottom: 5px; font-weight: bold; }
- input, button { padding: 8px; margin-bottom: 10px; }
- button { background: #007cba; color: white; border: none; cursor: pointer; margin-right: 10px; }
- button:hover { background: #005a87; }
- .log { background: #f5f5f5; border: 1px solid #ddd; padding: 10px; margin-top: 20px; height: 300px; overflow-y: auto; font-family: monospace; font-size: 12px; }
- .success { color: green; }
- .error { color: red; }
- .info { color: blue; }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>AJAX WordPress Import Test</h1>
- <p>This bypasses form submission issues by using AJAX requests.</p>
-
- <div class="form-group">
- <label>Host:</label>
- <input type="text" id="wp_host" value="10.15.10.8">
- </div>
-
- <div class="form-group">
- <label>Database:</label>
- <input type="text" id="wp_database" value="valtsu_valtsu">
- </div>
-
- <div class="form-group">
- <label>Username:</label>
- <input type="text" id="wp_username" value="">
- </div>
-
- <div class="form-group">
- <label>Password:</label>
- <input type="password" id="wp_password" value="">
- </div>
-
- <div class="form-group">
- <button onclick="testConnection()">Test Connection</button>
- <button onclick="importCategories()">Import Categories</button>
- <button onclick="importUsers()">Import Users</button>
- <button onclick="importPosts()">Import Posts</button>
- <button onclick="importComments()">Import Comments</button>
- <button onclick="clearLog()">Clear Log</button>
- </div>
-
- <div id="log" class="log"></div>
- </div>
- <script>
- function log(message, type = 'info') {
- const logDiv = document.getElementById('log');
- const timestamp = new Date().toLocaleTimeString();
- const className = type === 'error' ? 'error' : type === 'success' ? 'success' : 'info';
- logDiv.innerHTML += `<div class="${className}">[${timestamp}] ${message}</div>`;
- logDiv.scrollTop = logDiv.scrollHeight;
- }
- function getConfig() {
- return {
- wp_host: document.getElementById('wp_host').value,
- wp_database: document.getElementById('wp_database').value,
- wp_username: document.getElementById('wp_username').value,
- wp_password: document.getElementById('wp_password').value
- };
- }
- function makeRequest(action) {
- const config = getConfig();
- const params = new URLSearchParams({...config, action});
-
- log(`Making request: ${action}`, 'info');
-
- return fetch(`ajax_import_test.php?${params}`)
- .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');
- }
- if (data.logs) {
- log('--- Debug Logs ---', 'info');
- data.logs.forEach(logEntry => {
- const level = logEntry.level === 'error' ? 'error' : logEntry.level === 'success' ? 'success' : 'info';
- log(`[${logEntry.timestamp}] ${logEntry.message}`, level);
- });
- }
- } else {
- log(`✗ ${data.message} (${data.step})`, 'error');
- if (data.error) {
- log(`Error details: ${data.error.file}:${data.error.line}`, 'error');
- }
- }
- return data;
- });
- } else {
- // 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');
- });
- }
- })
- .catch(error => {
- log(`Network error: ${error.message}`, 'error');
- throw error;
- });
- }
- function testConnection() {
- makeRequest('test_connection');
- }
- function importCategories() {
- makeRequest('import_categories');
- }
- function importUsers() {
- makeRequest('import_users');
- }
- function importPosts() {
- makeRequest('import_posts');
- }
- function importComments() {
- makeRequest('import_comments');
- }
- function clearLog() {
- document.getElementById('log').innerHTML = '';
- }
- // Auto-focus username field
- document.addEventListener('DOMContentLoaded', function() {
- document.getElementById('wp_username').focus();
- });
- </script>
- </body>
- </html>
|