开发者

Inserting Record into database using Javascript!

Is it possible to insert data in a database using javascript only.

if yes then please post a simple example of it.

Since javascript is a client side language and not a server side,i think its n开发者_JAVA百科ot possible.

But then how to do it.


It is possible if you are using CouchDb http://couchdb.apache.org/

Apache CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript. CouchDB also offers incremental replication with bi-directional conflict detection and resolution.


Not directly. Any server-side language could be made to do this. Allowing end users to craft database queries however is just asking for it in the worst way.


The short answer is "no", javascript is a client side language, and has no ability to connect to a DB.

HOWEVER, the long answer is 'yes, but...'. There are a number of socket-libraries available in javascript (though most I saw seem to involve some flash/java trickery). Therefore, one could connect to the sql database (which would have the obvious security flaw) and submit the record from there.

It would be POSSIBLE, but absolutely stupid, difficult, and insecure.


Google: 'javascript odbc access'

First result

http://forums.asp.net/t/1285316.aspx

It IS possible. Though I don't know why you would want to do it. The code makes me think of when I did coding in ASP with ODBC support.


  1. No you can't simply do that.
  2. Javascript was created for Client Side which means it can be effective at Client Side.
  3. You can use HTTP Scripting technologies to exchange data between Server side and Client Side, for example Ajax would be nice practice.

Javascript can post data to server but there must be a back-end that can evaluate the data posted by Javascript.

I don't know but maybe later they will be such a technique or tech.


Yes, it would be possible to create the ActiveX objects that could connect to the database and execute a query.

No, I won't post an example. Putting the code in Javascript means that anyone can just view the code and get the connection string, getting access to view and edit your database. Let's just say that the TTL for the database would get really short...


Javascript is primarily a client-side language and has no access to a database without the use of a server side language to supplement it.

It is possible to use AJAX to post the data to the server, which would prevent the page from posting back, giving the appearance that the javascript had performed the action. But inevitably you will need something like ASP.NET, PHP, Ruby, ect. to capture the data and persist it to the database.

EDIT: Although not what I would consider a true database, there is a library called Taffy DB which is a client-side javascript database. Keep in mind that it is an in-memory database and it does not persist data to the server, so the data will be gone as soon as the user closes their browser. The Taffy DB FAQ covers it's ability to persist the data pretty well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜