alert(result_set)第一次显示null,但是当第二次调用此函数时,它显示正确的值。有一个简单的按钮正在执行此功能。第一次正确设置了全局变量lesson_no,但是第一次没有设置result_set。
这是我的jquery移动代码:
result_set=null;
//load database for the lesson
function loadLesson(lessonno){
$(".audio-pause").hide();
stopAudio();
clearMarker();
lesson_no = lessonno;
$("#lessonno").html("Lesson "+lesson_no);
$("#lessonImage").attr("src","lessons/Lesson_"+lesson_no+".png");
$('.audio-position').html("");
var sql = "select Lesson,x1,y1,x2,y2,starttime from lessoninfo where Lesson="+lesson_no;
db.transaction (function (transaction){
transaction.executeSql (sql, undefined, function (transaction, result){ //alert(result.rows.length);
result_set = result;
});
});alert(result_set)
setImageVariables();
markerCount=0;
$(".audio-play").show();
}
答案 0 :(得分:1)
Web SQL是异步的,就像AJAX一样。任何依赖于结果集的东西都必须在回调函数中完成。
function loadLesson(lessonno){
$(".audio-pause").hide();
stopAudio();
clearMarker();
lesson_no = lessonno;
$("#lessonno").html("Lesson "+lesson_no);
$("#lessonImage").attr("src","lessons/Lesson_"+lesson_no+".png");
$('.audio-position').html("");
var sql = "select Lesson,x1,y1,x2,y2,starttime from lessoninfo where Lesson="+lesson_no;
db.transaction (function (transaction){
transaction.executeSql (sql, undefined, function (transaction, result){ //alert(result.rows.length);
result_set = result;
alert(result_set);
setImageVariables();
markerCount=0;
$(".audio-play").show();
});
});
}