Skip to content

Instantly share code, notes, and snippets.

@TusharGirase
Created February 9, 2025 09:20
Show Gist options
  • Save TusharGirase/4a1a7a95aa1b042c4fc29e92773267cd to your computer and use it in GitHub Desktop.
Save TusharGirase/4a1a7a95aa1b042c4fc29e92773267cd to your computer and use it in GitHub Desktop.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>XML Upload Form</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body class="container mt-5">
<h2 class="mb-4">Upload XML Data</h2>
<form id="xmlForm">
<div class="mb-3">
<label class="form-label">Source Application ID</label>
<input type="text" class="form-control" id="sourceAppId" required>
</div>
<div class="mb-3">
<label class="form-label">Application CCR ID</label>
<input type="text" class="form-control" id="applicationCcrId" required>
</div>
<div class="mb-3">
<label class="form-label">Response</label>
<select class="form-select" id="response">
<option value="0">0</option>
<option value="1">1</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Choose XML Input Method</label><br>
<input type="radio" name="xmlInputMethod" value="file" id="xmlFileOption" checked> Upload File
<input type="radio" name="xmlInputMethod" value="text" id="xmlTextOption" class="ms-3"> Enter Text
</div>
<div id="fileUploadDiv" class="mb-3">
<input type="file" class="form-control" id="xmlFile" accept=".xml">
</div>
<div id="textInputDiv" class="mb-3 d-none">
<textarea class="form-control" id="xmlText" rows="5" placeholder="Enter XML here..."></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<script>
$(document).ready(function() {
$('input[name="xmlInputMethod"]').change(function() {
if ($('#xmlFileOption').is(':checked')) {
$('#fileUploadDiv').removeClass('d-none');
$('#textInputDiv').addClass('d-none');
} else {
$('#fileUploadDiv').addClass('d-none');
$('#textInputDiv').removeClass('d-none');
}
});
$('#xmlForm').submit(function(e) {
e.preventDefault();
let requestPayload = {
sourceAppId: $('#sourceAppId').val(),
applicationCcrId: $('#applicationCcrId').val(),
response: $('#response').val()
};
if ($('#xmlFileOption').is(':checked')) {
let file = $('#xmlFile')[0].files[0];
if (!file) {
alert('Please select an XML file');
return;
}
let reader = new FileReader();
reader.onload = function(event) {
requestPayload.xmlContent = event.target.result;
sendRequest(requestPayload);
};
reader.readAsText(file);
} else {
let xmlText = $('#xmlText').val().trim();
if (!xmlText) {
alert('Please enter XML content');
return;
}
requestPayload.xmlContent = xmlText;
sendRequest(requestPayload);
}
});
function sendRequest(payload) {
$.ajax({
url: 'http://localhost:8080/upload-xml', // Change this to your actual REST endpoint
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload),
success: function(response) {
alert('XML uploaded successfully!');
},
error: function() {
alert('Error uploading XML. Please try again.');
}
});
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment