SQL message boards at the Ajax JavaScript
It – Hardware & Software | Joyce Bergsman | 0 viewsIn JavaScript, SQL message boards
Tried to make a bulletin board this time using AjaSQL using the address search, zip code of last.
On Board also the use of Ajax, page entirely the activity light without the update.
This is because use of the AjaSQL, on the server-side source without touching is BBS only by the control logic of SQL database from the JavaScript side works.
Used to copy the database, just set the permissions of a simple SQLite.
* Since AjaSQL that is still under development, use minor v027. Also we have let used MD5 by Masanao Izumo Mr. conversion library (Advanced JavaScript techniques book) in the AjaSQL. Basic parts involved in the Ajax communication uses the jslb_ajax036.js, many provisional for Ajax libraries have used v036 ever. AjaSQL is note available both source and sample this site, since it currently is test version, Linux shell and PHP related to security.
- 1: Benefits of Ajax and the bulletin board system
2: Sample
3: A brief commentary
1: Benefits of Ajax and the bulletin board system
General Board sends user written data to the server, Server HTML of, along with storing the data saved past remarks and together and sends it back.
Sent from the Form element data in this case, send the, rewrite the whole page when received, and updates. Even if slight, is because rewrite all page 1 updated even one character.
I’ve seen by hand, using XMLHttpRequest, Ajax communication is like, like this page, updates the information in the page without updating the whole and receive only the minimum data required.
In other words, nimble low-latency interface creation. as a result,
2: Sample
Sample
(* The sample link above)
Browser behavior
win | Mac | Linux | |||||||||
N7 | M1 | E6 | O7 | o8 | N7 | M1 | E5 | s1 | N7 | M1 | K3 |
× | × |
This sample is the SQL statements issued from the JavaScript and append to search to a SQLite database, and comprises the functions of the Board.
This is only basic functionality was implemented, think, such as example, and acquiring the differential data in JavaScript one line of SQL statement + after receiving a simple incremental processing about, you make a pseudo chat sophistication and tune-up is possible still.
JavaScript/HTML side used source is as follows:
JavaScript side < font color = orange ><!—- >< script language = “JavaScript” charset = “UTF-8″ src = “./ajasql/jslb_ajax036.js” >< / script ><! – – interim Ajax Library jslb_ajaxxxx.js preliminary AjaSQL library ajasqlxxx.js– >< script language = “JavaScript” charset = “UTF-8″ src = “./ajasql/jslb_ajasql027.js” >< / script ><!– AjaSQL BBS for HTML construction of library ajasql_formsxxx.js– >< script language = “JavaScript” charset = “UTF-8″ src = “./ajasql/ajasql_ bbs001.js “>< / script >< script language =”JavaScript”><!–/ / startup process window.onload=doIni / / /SQL submit = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / / / said data requests function showMsg (oj) {/SQL statement created / / (table from column id descending max… the value of request) var sql = ‘ ‘+’ ‘ + sqlite01.tblName + SELECT * FROM ‘ ORDER BY id DESC LIMIT ‘+oj.form.max.value+’;'; /Select statement (sql, sqlite) send asql_sendSQL} search / search string containing data from the column “name”, “msg” var seachText = ‘ ‘ (oj) function seachMsg {var set var seachText = oj.form.sel.value /SQL statement creation / (max.value of request / id descending data, including sel.value in the column “name”, “msg”), / / search string ‘”%’+oj.form.sel.value+’% OR msg LIKE + ‘” %’+oj.form.sel.value+’% WHERE name LIKE ‘sql = SELECT * FROM’ + sqlite01.tblName +”‘” ‘ + ‘ ‘+’ ORDER BY id DESC LIMIT ‘+oj.form.max.value+’;'; /Select statement sent asql_sendSQL (sqlite, sql)} search for said data, including the search string / / from the column “msg” function seachMsgByText (oj, text) {set seachText = text /SQL text creation / / / search string (from table column “msg”, “%text%” / / max.value of requests one in descending order) var sql = ‘SELECT * FROM’ + sqlite01.tblName + ‘ “‘ + Text + % ‘ % WHERE msg LIKE” LIMIT ‘+oj.form.max.value+’;'; ‘+ ‘ORDER BY id DESC’ +’ /Select statement (sql, sqlite) send asql_sendSQL} / / before and after data request function showMsgByOFFSET (oj, offset) {‘LIMIT ‘ORDER BY id DESC ‘SELECT * FROM /SQL statement creation / / (/ / max.value of requests from the table column “id” descending from the offset of) var sql =’ + sqlite01.tblName +’ +’ + ‘ + offset + OFFSET oj.form.max.value+’ ‘; ‘; /Select statement sent asql_sendSQL (sqlite, sql)} / / said function insertMsg (oj) {if(oj.form.msg.value==’ message column ‘ | | oj.form.msg.value==” | | oj.form.name.value==”) return / / now breaks and, provisional ban, quotes to EM. /IE is? r? because had become no longer treatment in n/treatment / just in %0D%0A, and for other browser? r? n also capitalize msg = oj.form.msg.value.split(‘?n’).join(”) msg = msg.split(‘?r’).join(”) msg = msg.split(getRN()).join(” msg = encodeURI (msg)) to msg = decodeURI (msg) / / em escape msg = msg.split(‘, ‘).join(‘, ‘) msg = msg.split(‘).join(‘ by ‘) msg = msg.split(‘ “‘).join(‘” ‘) msg = msg.split(‘;’)… join (‘;’) msg = msg.split(‘&’).join(‘&’) ‘ INSERT INTO ‘+sqlite01.tblName + /SQL statements create a var sql = ‘ VALUES (‘ ‘”‘” ‘+oj.form.name.value+’ /id +”,’ / / name +’ + msg + ‘+’ Null, ‘”, “‘ / / message + ‘”, ‘ “” ‘”#SERVER_NOW# / / +”,’ / / hour + / + ‘); ‘; / / Said after sending specified sqlite.ini.callback = onInserted /INSERT sentence onInserted callbacks during startup for asql_sendSQL (sqlite, sql) / / said clear oj.form.msg.value = ‘ ‘} / / / / callback function / / var ary = ‘ ‘ / / callback function 1 function onSelected (resoj, reqoj) {array of response data (array [row, column In you can retrieve the) ary = getRowColArray (resoj, reqoj) if(ary.length>1) {to / / remarks for display DIV output msges.innerHTML=outputMsges(ary, headBgcolor, rowsBgcolors)} click on background color else ajasql_bbs_last = true / / search word if (seachText! = ‘ ‘) {var wkmsges = msges.innerHTML.split(seachText) var color = “< span style = ‘ background-color: #aacccc ‘ >” + seachText + “</span>” msges.innerHTML = wkmsges.join(color); }} / / Callback function 2 function onInserted (resoj, reqoj) {to / / remarks for display DIV ary = getRowColArray array of response data (which you can retrieve with array rows, columns) (resoj, reqoj) msges.innerHTML= output “—” + outputMsges (ary, headBgcolor, rowsBgcolors) / / display = sqlite.ini.callback onInserted2 showMsg (bbsform); } / / Callback function 3 function onInserted2 (resoj, reqoj) {to / / remarks for display DIV ary = getRowColArray array of response data (which you can retrieve with array rows, columns) (resoj, reqoj) output, msges.innerHTML=outputMsges(ary, headBgcolor, rowsBgcolors)} /–>< / script >< style CSS * / / * short * / </style> CSS * / / * stands for * / / * remarks for display div > / * input form
In JavaScript, SQL message boards
- 1: Benefits of Ajax and the bulletin board system
2: Sample
3: A brief commentary
3: A brief commentary
Then a brief commentary about the front page sample
For information about SQL
SQL-Structured Query Language (structured query language), is the worldwide standard developed by IBM as a language for database operations for. It is possible to run SQL statements and recently used better Web apps in the PGSQL or MySQL or Microsoft SQL Server include SQL database name is a myriad of other SQL compliant database out there, are they a little accent.
This uses the SQLite database bundled with PHP5 or later. This is simple in both per-file distribution, user rights also follow the operating system file permissions. Therefore, must not be owner Web Server user (nobody, apache) are. (However, powerful SQL commands, such as CREATE or DROP default in AjaSQL side OS command, of course, so impervious to. They are recommended DB administrator to do individually. )
SQL statement used in the AjaSQL Bulletin Board
Database processing to first in the General Board is to load the said data was accumulated. Making a function called showMsg (oj), the following sample, and has issued a statement. Remarks / / data requests function showMsg (oj) {(max.value of requests in the id column in descending order from the table) /SQL statements create / var sql = ‘ ‘+’ ‘ + sqlite01.tblName + SELECT * FROM ‘ ORDER BY id DESC LIMIT ‘+oj.form.max.value+’;'; /SELECT statement (sql, sqlite) send asql_sendSQL} in the above for example, SQL statements are created, synthesized with variables such as oj.form.max.value is something like the following easy to write. descending to the id column from the database table, called mydb1, out of 10. ‘ SELECT * FROM mydb1 ORDER BY id DESC LIMIT 10; ‘; Meaning and to explain the break will occur. SELECT columns (tab) (all) from (mydb1 table) FROM mydb1 ORDER BY id DESC (case id column in descending order, ASC ascending) LIMIT n/a limit); ID have mastered said every numbered automatically in this table mydb1. This means a new larger id said. So what n/a number of matter by a simple one-line statement is not can receive 10 results, latest tweets instantly from JavaScript “.
Callback function, the mechanism of the receiving
In send Ajax requests from the XMLHttpRquest object after the send(), oj.onreadystatechange() and oj.onload() that designed that receive incoming data object within the event method. This time using AJAX libraries is to pass it to the callback function specified by the author, at the time of receiving all data.
Further, in initial settings in the AjaSQL callback: ‘onSelected’, / / received during initial boot function name or write like this, written like the initial startup function name iniOj.callback = onSelected / / when received from for example SQL to send the following Send incoming data takes asql_sendSQL (sqlite, sql) /SELECT sentence in the callback functions:, Be as treatable in JavaScript is. GetRowColArray() below, an array of the response data and HTML table of outputMsges() function onSelected (start when they arrive from the server) / / callback function is a function that can be used in the AjaSQL library (for details, see the source in each library) (resoj, reqoj) {ary = array of response data (which you can retrieve with array rows, columns) if(ary.length>1 getRowColArray (resoj, reqoj)) {/ / table of the output for display DIV statement to msges.innerHTML=outputMsges(ary, headBgcolor, rowsBgcolors)}} AjaSQL library in gateway cities such as garbled characters coping such as Safari and KHTML, like a cross-browser drag and transparency effects processing, etc. until that address That has become available functions.
Database SQLite (mydb_bbs.db)
This time though, so distribute the database to the file unit uses SQLite. SQLite out table structure is shown below. The same sample DB up to mydb1-5 copy beforehand so should put the table schema, can be used.
CREATE TABLE mydb1 (id integer primary key, /id name text, / / name of the msg text, / / message memo text, / / note date text, / / on ip text /ip);
Data is stored in the following. 1 | test | test | | n/a :26:02 | 2 | test | Hi | | n/a :26:09 | 3 | Tests | Hi, AI continued us | | n/a :40:09 | 4 | aaa | aaa | | n/a :12:20 | : :
Configuration files and permissions
Configuration file is a SQLite database file and a PHP library for Ajax, AjaSQL, three-tier library for BBS as a server-side gateway. Roto Ajax Library is responsible for sending and receiving using the XMLHttpRequest, it using the AjaSQL library, responsible for control of the SQL database. It is a form of riding on to remark and the form of output for HTML generation library for BBS.
Incoming search terms:
- ajax bulletin board (1)
- ajax message board script (1)
- javascript bulliten board (1)
- msg split sql (1)
Additional items from "It – Hardware & Software"
- Lenovo ThinkPad X60
- BOSE SoundDock review! take advantage of more! iPod mini
- pcDtrying to take advantage of the drive
- PHP5installing and configuring
- 10less than ten thousand yen good find the! KDL-16M1
- to reduce the size of the image material3one+αmethod of let’s reduce the image
- 2the title of the line1line fit to2ways
- world firstSideShowequipped withASUS W5Fe
- with easy installation, good sound easy to enjoy YHT-S401
- Office Spesialist Word, ExcelofExpertfull marks! her senior2reason for the perfect score for both subjects