スイッチをおしたらほかのページの情報を出力する
基本
<html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>tryjquery_hide_p test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("input#update").click(function(){ alert("helloworld"); $.get("test.html",function(data){ $("div#contents").text(data); }); }); }) </script> </head> <body> <p> This is a pen </p> <input type="button" value="Update" id="update"></input> <div id=contents></div> </body> </html>
データベースの内容を出力
<html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>tryjquery_hide_p test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("input#update").click(function(){ alert("helloworld"); $.get("/cgi-bin/test.rb",function(data){ $("div#contents").html(data); }); }); }) </script> </head> <body> <p> This is a pen </p> <input type="button" value="Update" id="update"></input> <p> データベースの内容 </p> <div id=contents></div> </body> </html>
/cgi-bin/test.rb
#!/usr/local/bin/ruby require 'rubygems' require 'cgi' require 'fileutils' require 'sqlite3' cgi=CGI.new def error_cgi print "Content-Type:text/html;charset=EUC\n\n" print "*** CGI Error List ***<br />" print "#{CGI.escapeHTML($!.inspect)}<br />" $@.each {|x| print CGI.escapeHTML(x), "<br />"} end begin puts "Content-type: text/html charset=UTF-8\n\n" db=SQLite3::Database.new("syoku.sqlite3") a=db.execute("select * from update_info") #puts "hello" #print a[0][1] puts "<p>Update Information</p>" puts "<table border=1>" puts "<tr><td>update_date</td><td>"+a[0][0]+"</td></tr>" puts "<tr><td>update_flg</td><td>"+a[0][1].to_s+"</td></tr>" puts "</table>" end