UrlManipulator-php/web-client/script.js

56 lines
1.5 KiB
JavaScript

function manipulateUrl() {
var url = $('#url').val();
$.ajax({
type: 'POST',
url: '../server/index.php',
data: { url: url },
dataType: 'json',
success: function (result) {
displayResult(result);
},
error: function (xhr, status, error) {
displayError(error);
}
});
}
function displayResult(result) {
console.log(result);
var resultContainer = $('#result-container');
resultContainer.empty();
if (result.hasOwnProperty('error')) {
resultContainer.append('<p class="error">' + result.error + '</p>');
} else {
// Update the text area with the modified URL
$('#url').val(result.after.replace(/&amp;/g, '&'));
}
}
function displayError(error) {
var resultContainer = $('#result-container');
resultContainer.empty();
resultContainer.append('<p class="error">Error: ' + error + '</p>');
}
// Function to reset the session
function resetSession() {
var resultContainer = $('#result-container');
var textArea = $('#url');
$.ajax({
type: 'POST',
url: '../server/reset_session.php', // Adjust the path accordingly
success: function () {
alert('Session has been reset.');
resultContainer.empty(); // Clear the error display
textArea.val(''); // Clear the text area
// You can perform additional actions after resetting the session if needed
},
error: function (xhr, status, error) {
console.error('Error resetting session:', error);
}
});
}