I am trying to use AJAX in my project to handle images (load more info and delete). Loading is working, but when i try to delete any of them, I recieve error 500 and php script is not used.
var page = 1;
var selected = [];
var mediaAll = [];
var jsont = JSON.stringify({"action": "loadMedia", "page": page});
AJAXcall(jsont, "loadMedia");
function AJAXcall(data, action){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
console.log(xhttp);
if (this.readyState == 4 && this.status == 200) {
if(action=="loadMedia"){
var media = JSON.parse(this.responseText);
mediaAll = [];
mediaAll = mediaAll.concat(media);
mediaLoaded();
}else if(action=="loadMoreMedia"){
var media = JSON.parse(this.responseText);
mediaAll = mediaAll.concat(media);
mediaLoaded();
}else if(action=="deleteMedia"){
response = JSON.parse(this.responseText);
console.log(response);
page = 1;
if(response == true){
AJAXcall(jsont, "loadMedia");
}
}
}
};
xhttp.open("POST", "./libs/img_handler.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(data);
}
function deleteSingle(){
if(selected.length === 1){
if (confirm('sure?')) {
var dataS = {"action": "deleteMedia", "id": selected[0]};
dataDel = JSON.stringify(dataS);
AJAXcall(dataDel, "deleteMedia");
}
}
}
function loadMore(){
page++;
var jsont = JSON.stringify({"action": "loadMoreMedia", "page": page});
AJAXcall(jsont, "loadMoreMedia");
}
When used function loadMore
XMLHttpRequest { onreadystatechange: onreadystatechange(), readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, responseURL: "http://localhost:8888/project/libs/img_handler.php", status: 200, statusText: "OK", responseType: "", response: "..."}
When used function deleteSingle
XMLHttpRequest { onreadystatechange: onreadystatechange() , readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, responseURL: "http://localhost:8888/project/libs/img_handler.php", status: 500, statusText: "Internal Server Error", responseType: "", response: "" }
deleteSinglecode that's killing the system... we'd need to see what that is.