Files
crm.clientright.ru/test_document_upload_form.html

79 lines
2.9 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>Test Document Upload</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>Тест загрузки документа (как в CRM)</h1>
<form id="testUploadForm" enctype="multipart/form-data">
<input type="hidden" name="module" value="Documents">
<input type="hidden" name="action" value="SaveAjax">
<input type="hidden" name="document_source" value="Vtiger">
<div>
<label>Название документа:</label><br>
<input type="text" name="notes_title" value="Test Document Upload" required>
</div>
<div style="margin-top: 10px;">
<label>Файл:</label><br>
<input type="file" name="filename" required>
</div>
<div style="margin-top: 10px;">
<label>Пользователь:</label><br>
<input type="hidden" name="assigned_user_id" value="1">
<span>Admin (ID: 1)</span>
</div>
<div style="margin-top: 10px;">
<label>Папка:</label><br>
<input type="hidden" name="folderid" value="1">
<span>Default (ID: 1)</span>
</div>
<div style="margin-top: 20px;">
<button type="submit">Загрузить документ</button>
</div>
</form>
<div id="result" style="margin-top: 20px; padding: 10px; border: 1px solid #ccc; display: none;"></div>
<script>
$(document).ready(function() {
$('#testUploadForm').on('submit', function(e) {
e.preventDefault();
var formData = new FormData(this);
// Показываем что отправляем
console.log('Отправляем данные:');
for (var pair of formData.entries()) {
console.log(pair[0] + ': ' + pair[1]);
}
$('#result').show().html('<div style="color: blue;">Загружаем...</div>');
$.ajax({
url: 'index.php',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
console.log('Success response:', response);
$('#result').html('<div style="color: green;"><strong>Успех!</strong><br><pre>' + JSON.stringify(response, null, 2) + '</pre></div>');
},
error: function(xhr, status, error) {
console.log('Error response:', xhr.responseText);
$('#result').html('<div style="color: red;"><strong>Ошибка ' + xhr.status + ':</strong><br>' + xhr.responseText + '</div>');
}
});
});
});
</script>
</body>
</html>