$('.workspace__header div .fa-plus').on('click', function(){
$.ajax({
type: "POST",
url: "./admin.php",
data: "action=addProject",
});
});
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$data = json_decode(file_get_contents("data.json"));
$projects = $data -> projects;
if($_POST['action'] && $_POST['action'] === 'addProject'){
$data -> projects[] = array(
'name'=> "",
'author'=> "",
'address'=> "",
'complex'=> "",
'description'=> "",
);
}
$currentProject = $_POST['currentProject'];
if($_POST['action'] && $_POST['action'] === 'removeProject'){
array_splice($data -> projects, $currentProject, 1);
}
/* */
echo "<pre>";
print_r($data);
echo "<pre/>";
file_put_contents('data.json',json_encode($data));
<main>
<section class="admin__main-content">
<div class="workspace">
<div class="workspace__header">
<p>Проекты</p>
<div>
<i class="fa fa-trash" aria-hidden="true"></i>
<i class="fa fa-plus" aria-hidden="true"></i>
</div>
event.preventDefault();
все бы их должен был выключить ,но даже он не помогает. let projectsArr;
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
};
rawFile.send(null);
}
readTextFile("./data.json", function(text){
projectsArr = JSON.parse(text);
});
const
projectStage = document.querySelector('.workspace__main');
let
project = document.querySelector('.project');
for (let i = 0; i < (projectsArr.projects.length - 1);i++){
let
projectClone = project.cloneNode(project);
projectStage.appendChild(projectClone);
}
document.querySelectorAll('.project').forEach(function (el,index) {
el.querySelectorAll('.workspace__main-complex div p')[1].innerHTML = projectsArr.projects[index].name;
el.querySelectorAll('.workspace__main-address div p')[1].innerHTML = projectsArr.projects[index].address;
el.querySelectorAll('.workspace__main-authors div p')[1].innerHTML = projectsArr.projects[index].author;
el.querySelectorAll('.workspace__main-description div p')[1].innerHTML = projectsArr.projects[index].description;
});
$('.workspace__header div .fa-plus').on('click', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "./index.php",
data: "action=addProject",
});
});
<div>
<i class="fa fa-trash" aria-hidden="true"></i>
<i class="fa fa-plus" aria-hidden="true"></i>
</div>
document.querySelector('.workspace__header div .fa-plus').onclick = function () {
$.ajax({
type: "POST",
url: "./index.php",
data: "action=addProject",
});
};
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$data = json_decode(file_get_contents("data.json"));
$projects = $data -> projects;
if($_POST['action'] && $_POST['action'] === 'addProject'){
$data -> projects[] = array(
'name'=> "",
'author'=> "",
'address'=> "",
'complex'=> "",
'description'=> "",
);
}
$currentProject = $_POST['currentProject'];
if($_POST['action'] && $_POST['action'] === 'removeProject'){
array_splice($data -> projects, $currentProject, 1);
}
/* */
echo "<pre>";
print_r($data);
echo "<pre/>";
file_put_contents('data.json',json_encode($data));