0

データベースからデータセットを取得するコードがあります。

var pg = require('pg').native;

// Format: "postgres://YourUserName:YourPassword@localhost:5432/YourDatabase";
var dbUrl = "url hidden";

function testConn(onDone) {
    pg.connect(dbUrl, function(err, client) {
        client.query("SELECT ad FROM alert WHERE ad = 132", function(err, result) {

            console.log("ad is: %d", result.rows.length);
            console.log("ad value is: %d", result.rows[0].ad_id );
            onDone();
        });
    });
}

// Let's call the function
testConn(disconnectAll)

// Disconnect all connections
function disconnectAll() {
    pg.end();
}

そして、これは問題なく動作し、結果を取得してターミナルに表示します。

私が達成したいのは、これらの結果をコンソールではなく html ページに表示することです。私はすでにフロントエンド ページ (jquery モバイルを使用) を開発しており、代わりにこのページにデータベースの値を表示したいと考えています。コンソール。

誰でもこれを行う際の正しい道を教えてもらえますか? たとえば、div 要素を使用してデータを非表示/表示できることを知っています。結果を取得して、このような要素に HTML ページに表示するための最良の方法を知る必要があります。

すべての助けに感謝します!

4

1 に答える 1

1

このようなものですが、これはグーグルのみからのコピーです

  response.writeHead(200, {"Content-Type": "application/json"});
  var otherArray = ["item1", "item2"];
  var otherObject = { item1: "item1val", item2: "item2val" };
  response.write(
    JSON.stringify({ 
      anObject: otherObject, 
      anArray: otherArray, 
      another: "item",
    })
  );
于 2013-02-11T05:51:45.640 に答える