简体   繁体   English

检查数据库是否存在于JavaScript中

[英]Check if database exists in JavaScript

openDatabase(DB_SHORT_NAME, DB_VERSION, DB_DISPLAY_NAME, DB_MAX_SIZE)

in JavaScript opens database or creates the database if not exists in browser. 在JavaScript中打开数据库或创建数据库(如果浏览器中不存在)。

Is there any way I can able to check if database exists or not in browser? 有什么方法可以检查浏览器中是否存在数据库?

JavaScript coined HTML5 is the only way to do this; JavaScript创造的HTML5是实现此目的的唯一方法。 you can use mobile libraries such as Phonegap or Titanium which will also render a Javascript library - however these are for mobile app development only; 您可以使用诸如Phonegap或Titanium之类的移动库,它们也将呈现Javascript库-但是这些库仅用于移动应用开发; there mobile web versions are abysmal so don't consider converting it to mobile web and editing the fluid width values! 那里的移动网络版本太糟糕了,所以不要考虑将其转换为移动网络并编辑流体宽度值!

Do not forget that not all HTML5 browsers even support the database feature. 不要忘记, 并非所有 HTML5浏览器甚至都支持数据库功能。 It is limited. 它是有限的。 And so is support and it really is about finding out tutorials and trial and error. 支持也是如此,它实际上是关于查找教程以及反复试验的信息。 Those people that do; 那些做的人; either blog it, or don't have a blog to post experiences (or so lazy and frustrated blogging about the headache is the last thing!). 要么通过博客发布博客,要么没有博客可以发布经验(或者,关于头痛的懒惰而沮丧的博客是最后一件事!)。

http://www.tutorialspoint.com/html5/html5_web_sql.htm http://www.tutorialspoint.com/html5/html5_web_sql.htm

https://stackoverflow.com/questions/8007917/check-if-db-exists-and-dropping-db-in-sqllite-ios https://stackoverflow.com/questions/8007917/check-if-db-exists-and-dropping-db-in-sqllite-ios

Some of many sites. 许多网站中的一些。 ( shudders for the angry negative mob ) 为愤怒的暴民颤抖

You could try something like this: 您可以尝试这样的事情:

// Uses jQuery
var db="mydb.db";
$.ajax({
    url:db,
    type:'HEAD',
    error: function()
    {
        //file not exists
    },
    success: function()
    {
        //file exists
    }
});

Here is the code for checking, whitout using jquery 这是使用jquery进行检查和检查的代码

    function dbExists(db)
    {
        var http = new XMLHttpRequest();
        http.open('HEAD', db, false);
        http.send();
        return http.status!=404;
    }

var db="mydb.db";
dbExists(db);

Code is not really a live code; 代码并不是真正的实时代码。 nor should I expect it to be - I know it is ugly.. but you get the idea surely. 我也不应该期望它是-我知道它很丑..但是您肯定会明白。 HTML5 local database and storage is poor. HTML5本地数据库和存储很差。 What is it you are trying to do? 您想做什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM