-1

I m developing Android application. I'm integrating the sqlite into my application https://github.com/brodyspark/PhoneGap-sqlitePlugin-Android The below error is coming

Uncaught TypeError: Object # has no method 'exec'

while using the following code

window.sqlitePlugin.openDatabase({name: "DB"});

Rails AJAX request 500 Internal Server Error details

I have a form partial as follows:

_internet_service_form.html.erb

<%= simple_form_for @internet_service, remote: true do |f| %>
  <%= f.input :start_date %>
  <%= f.button :submit %>
<% end %>

When I render it in the new action of the controller, it returns a 500 internal server with no further explanation.

When I render it in the edit action of the controller, it renders correctly.

If I replace the partial with a text block with no rails tags in it, it renders correctly, so I know it's not a routing error.

new.js.erb

$("#result-content").html("<%= escape_javascript(render(partial: 'new')) %>");

new.html.erb

<%= render partial: 'internet_service_form' %>

internet_service_controller.rb

def new
  @internet_service = InternetService.new
end

def edit
  @internet_service = InternetService.find(params[:id])
end

These actions are being performed through AJAX, and the most useful logs I'm getting out of the development log are:

Started POST "/accounts/29/internet_services/new.js" for 10.12.68.100 at 2013-02-13 00:28:11 +1300
Processing by InternetServicesController#new as JS
  ... snip ...
  Rendered internet_services/_internet_service_form.html.erb (14.9ms)
  Rendered internet_services/_new.html.erb (24.3ms)
  Rendered internet_services/new.js.erb (32.2ms)
Completed 500 Internal Server Error in 231ms
4

3 回答 3

1

您需要确保在打开数据库之前等待 Cordova 加载。

根据项目中的 README.md

// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
  var db = window.sqlitePlugin.openDatabase({name: "my.db"});
  // ...
}
于 2014-08-27T02:03:14.830 回答
1

https://github.com/xuexueMaGicK/Gift-App

看到这个链接 js 文件在这里可用 数据库连接在那里

 window.addEventListener("DOMContentLoaded", init);

function init() {
pageshow = document.createEvent("Event");
pageshow.initEvent("pageshow", true, true);

tap = document.createEvent("Event");
tap.initEvent("tap", true, true);

pages = document.querySelectorAll('[data-role="page"]');
numPages = pages.length;

links = document.querySelectorAll('[data-role="link"]');
numLinks = links.length;

//checkDB();
document.addEventListener("deviceready", checkDB, false);
 }

/ ******************************* 一般交互 **************** *************** /

 function checkDB() {
 navigator.splashscreen.hide();

 database = openDatabase('data', '', 'data', 1024 * 1024);

 if (database.version === '') {

    database.changeVersion('', '1.0', createDB, function (tx, err) {
        console.log(err.message);
    }, function (tx, rs) {
        console.log("Increment transaction success.");
    });
    addNavHandlers();
} else {
    addNavHandlers();
}

}

function createDB(db) 
{

/*******Create Table Gifts********/

 db.executeSql('CREATE TABLE "gifts" ("gift_id" INTEGER PRIMARY KEY AUTOINCREMENT, "name_id" INTEGER, "occasion_id" INTEGER, "gift_idea" VARCHAR(45))', [], function (tx, rs) {
    console.log("Table gifts created");
}, function (tx, err) {
    console.log(err.message);
});
/*******Create Table Names********/
db.executeSql('CREATE TABLE "names" ("name_id" INTEGER PRIMARY KEY AUTOINCREMENT, "name_text" VARCHAR(80))', [], function (tx, rs) {
    console.log("Table names created");
}, function (tx, err) {
    console.log(err.message);
});
/*******Create Table Occasions********/
db.executeSql('CREATE TABLE "occasions" ("occasion_id" INTEGER PRIMARY KEY AUTOINCREMENT, "occasion_text" VARCHAR(80))', [], function (tx, rs) {
    console.log("Table occasions created");
}, function (tx, err) {
    console.log(err.message);
});

}

于 2014-08-27T06:37:18.387 回答
0

在 Manifest.xml 中,您必须添加与 SQLite 相关的插件。然后它将起作用。

于 2013-09-17T12:26:33.057 回答