I'm struggling with updating my json array properly. Even though I am able to remove an object from the array, when I check the server's json array, it still appears unchanged. What could be causing this issue?
Below is the function I am currently using:
$(function() {
$("#rectangle-delete").click(function() {
var selection = $('#templateSelection > option:selected').text();
var json = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'type': 'POST',
'contentType':"application/json",
'url': 'server/php/data/' + selection,
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
var ID_clicked = $(".rectangle.selected.targeted").attr('id');
console.log('initial array is ' + json);
json.some(function(e) {
if (e.ID === ID_clicked) {
var values = json.map(function(e) { return e.ID; });
var index = json.map(function(e) { return e.ID; }).indexOf(ID_clicked);
var data = JSON.stringify(json[index]);
json.splice(index, 1);
return true; // stop the array loop
}
});
console.log('new array is ' + json);
});
});
In the console, I can see:
initial array is [object Object],[object Object],[object Object]
and then
new array is [object Object],[object Object]
However, despite these changes, the actual json
file on the server remains unaffected.