I am using redips drag and drop jquery plugin and I would like to cancel drop when status from server is false.
Here is the sample of my code.
My system works like this, when you drag an element, I send data to server to check, if it's successfully checked, it will return with true or false. if it is false I should cancel drop and the element return to the previous location.
var redipsInit; // define redipsInit variable
redipsInit = function () {
var rd = REDIPS.drag;
rd.init();
rd.hover.colorTd = '#9BB3DA';
rd.event.moved = function (){
var objOld = rd.objOld;
REDIPS.drag.dropMode ='switch';
};
// element is dropped
rd.event.droppedBefore = function () {
var data //are data i send to server to process
$.ajax({
url: 'http://127.0.0.1/server/2',
data: data,
type: "get",
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
timeout:20000,
success: function (data) {
var status = data.status;
if(status == true){
return true; /*if status is true i should drag and drop successfully*/
} else{
var errors =data.errorjson;
if(errors == 1){
alert("alert");
return false;//here is the problem, it is always returning true instead of false in order to cancel my drop
}
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert("alert");
return false;
}
});
};
};