can you please tell me how to call synchronise method in jquery or java script. Actually problem is that I call one function on click button.And get some value .While getting below function call and i am getting undefined value after some time i will get value. I will explain with my example. 1)I need to get CASENAME value on click del button.I am getting the value from data base .While getting this deleteFolder function call .There i will get value undefined. then after i will get real value here alert("CASENAME"+CASENAME);I think i need to synchronise this method as we do in java.?
$(document).on('click', '.del', function(event) {
ROW_ID = $(this).closest(".caseRowClick").attr("id");
//getCaseNameValue();
db.transaction(function (tx) {
var caseName_h = $('.caseName_h').val();
$yoursql = 'SELECT CaseName FROM CaseTable WHERE id ='+ ROW_ID;
tx.executeSql($yoursql, [], function (tx, results) {
CASENAME=results.rows.item(0).CaseName;
alert("CASENAME"+CASENAME);
});
});
deleteData();
deleteFolder();
$(".ctrl").toggleClass("togg");
event.stopPropagation();
});
function deleteFolder(){
alert(CASENAME);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
console.log("Root ================********************* " + fs.root.fullPath);
TEXTFILE_PATH=fs.root.fullPath;
fs.root.getDirectory(CASENAME, {create: true, exclusive: false},
function(dirEntry) {
dirEntry.removeRecursively(successfullyDelete, faildelete)
});
});
}
You should be passing that variable ( CASENAME ) around...
or the variable should be in the scope of both the functions.
Try this:
$(document).on('click', '.del', function (event) {
var ROW_ID = $(this).closest(".caseRowClick").attr("id");
var CASENAME;
//getCaseNameValue();
db.transaction(function (tx) {
var caseName_h = $('.caseName_h').val();
$yoursql = 'SELECT CaseName FROM CaseTable WHERE id =' + ROW_ID;
tx.executeSql($yoursql, [], function (tx, results) {
CASENAME = results.rows.item(0).CaseName;
alert("CASENAME" + CASENAME);
});
});
deleteData();
deleteFolder(CASENAME);
$(".ctrl").toggleClass("togg");
event.stopPropagation();
});
function deleteFolder(CASENAME) {
alert(CASENAME);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log("Root ================********************* " + fs.root.fullPath);
TEXTFILE_PATH = fs.root.fullPath;
fs.root.getDirectory(CASENAME, {
create: true,
exclusive: false
},
function (dirEntry) {
dirEntry.removeRecursively(successfullyDelete, faildelete)
});
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.