I have a bunch of images that are showing up in a gallery. From a json file.
each <img>
has an id,
On click a jquery script excutes that takes the id
and passes it back through a ajax to php script that should remove that image from the json.
Here is the code I have:
function deletebtn(){
$(".delete-button").click(function(event) {
var deleteme = event.target.id;
$("#"+ deleteme).remove();
var jsondelete = "http://localhost/wordpress/api/json/gallery.json";
$.getJSON( jsondelete, {
format: "json"
})
.done(function( data ) {
delete data.images.+deleteme;
var data = JSON.stringify(data);
$( "#json_delete" ).html(data);
var brick = $( "#json_delete" ).html();
$.ajax({
url: 'http://localhost/gallery/deletejson.php',
method: 'POST',
data: {
"json": brick,
},
success: function(result) {
console.log("SAVED JSON");
},
error: function(result) {
alert("DID NOT SAVE JSON");
}
});
});
});
}
The issue im having is I cant use this
delete data.images.+deleteme;
If turn this function into
delete data.images.img_177;
this works. How ever im trying to pass the var $deleteme
var $deleteme = event.target.id;
which if you use alert or console log is
img_177
Am I missing something?