test
This commit is contained in:
@@ -61,32 +61,11 @@ $(function() {
|
||||
slide: function(event, ui) {
|
||||
$("#text_ad").text(getText(ui.value));
|
||||
$("#amount").text(ui.value);
|
||||
saveDataToServer(ui.value);
|
||||
//localStorage.setItem("sliderValue", ui.value.toString());
|
||||
localStorage.setItem("sliderValue", ui.value.toString());
|
||||
updateFace(ui.value);
|
||||
}
|
||||
});
|
||||
|
||||
function saveDataToServer(value) {
|
||||
// Data k odeslání na server
|
||||
var dataToSave = {
|
||||
sliderValue: value,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "saveData.php", // Název skriptu na serveru
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(dataToSave),
|
||||
success: function(response) {
|
||||
console.info(response);
|
||||
},
|
||||
error: function(error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var savedValue = localStorage.getItem("sliderValue");
|
||||
if (savedValue) {
|
||||
slider.slider("value", parseInt(savedValue));
|
||||
@@ -103,6 +82,7 @@ $(function() {
|
||||
});
|
||||
|
||||
function updateFace(value) {
|
||||
saveSliderValue(value);
|
||||
var face = $(".face-wrapper").children();
|
||||
|
||||
switch (value) {
|
||||
@@ -133,6 +113,22 @@ $(function() {
|
||||
}
|
||||
}
|
||||
|
||||
function saveSliderValue(value) {
|
||||
// Odeslat aktuální hodnotu posuvníku na server
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "saveData.php",
|
||||
data: JSON.stringify({ sliderValue: value }),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
success: function(response) {
|
||||
console.log("Slider value saved successfully!");
|
||||
},
|
||||
error: function(error) {
|
||||
console.error("Error saving slider value:", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function removeClass() {
|
||||
$(".face-wrapper").children().removeClass("case1 case2 case3 case4 case5 case6");
|
||||
}
|
||||
|
||||
@@ -2,13 +2,19 @@
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
// Uložte hodnotu obličeje (a další data) na serveru
|
||||
file_put_contents('adf/data.json', json_encode($data));
|
||||
// Zkontrolovat, zda je klíč sliderValue v datech
|
||||
if (isset($data['sliderValue'])) {
|
||||
// Uložit hodnotu posuvníku na serveru
|
||||
$filePath = 'adf/sliderValue.json';
|
||||
file_put_contents($filePath, json_encode(['sliderValue' => $data['sliderValue']]));
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
echo json_encode(['error' => 'Invalid data format']);
|
||||
}
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
// Kontrola existence souboru
|
||||
$filePath = 'adf/data.json';
|
||||
$filePath = 'adf/sliderValue.json';
|
||||
if (file_exists($filePath)) {
|
||||
// Načtení obsahu souboru
|
||||
$fileContent = file_get_contents($filePath);
|
||||
@@ -27,3 +33,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Ladící výstup
|
||||
error_log(print_r($_POST, true));
|
||||
error_log(print_r($_FILES, true));
|
||||
?>
|
||||
|
||||
0
ADF/sliderValue.json
Normal file
0
ADF/sliderValue.json
Normal file
Reference in New Issue
Block a user