tailieunhanh - Xây dựng ứng dụng cho Android với HTML, CSS và javascript - part 11

Tham khảo tài liệu 'xây dựng ứng dụng cho android với html, css và javascript - part 11', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | In some cases you might want to branch based on the type of error to decide whether you should return true or false. Table 5-1 at the end of this chapter shows the current possible error codes according to the W3C Web SQL Database working draft specification. You may have noticed that the error handler function accepts a transaction object in addition to the error object. It s conceivable that in some cases you might want to execute a SQL statement inside the error handler perhaps to log the error or record some metadata for debugging or crash-reporting purposes. The transaction object parameter allows you to make more executeSql calls from inside the error handler like so this is just an example it will not run unless you ve created the errors table that it refers to function errorHandler transaction error alert Oops. Error was Code INSERT INTO errors code message VALUES return false Please take special note of the fact that we have to return false from the error handler if we want the executeSql statement to run. If we return true or nothing at all the entire transaction including this SQL statement will be rolled back thereby preventing the desired result. Although I won t be doing so in my examples you should know that you can also specify success and error handlers on the transaction method itself. This gives you a convenient location to execute code after a long series of executeSql statements have completed. Oddly the parameter order for the transaction method s callbacks is defined to be error then success the reverse of the order for executeSql . Here s a version of the createEntry function with transaction callbacks added toward the end don t add these to because we haven t defined either of these methods function createEntry var date var calories calories .val var food food .val function transaction INSERT INTO

TỪ KHÓA LIÊN QUAN