aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Can i connect a js file to a database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can i connect a js file to a database?" Watch "Can i connect a js file to a database?" New topic
Author

Can i connect a js file to a database?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

Dear Ranchers,

Can I connect, a js file to a database.if yes please let me know or share the link for the same. I tried googling, but it was not displaying


http://www.lifesbizzare.blogspot.com || OCJP:81%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42910
    
  68
What do you mean by that? Javascript runs on the client, whereas the DB is on the server. Are you maybe asking : how can Javascript code call server-side code which in turn calls the DB? If so, then a library like jQuery or Prototype may be involved.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Do you mean to connect to database from JavaScript? If that's the case then yes, you can, but it's not recommended to do so (mostly for security issues). It is a bad practice so it would be better to choose a server side language to establish a connection to db.

Also I think there is a separate subforum for these questions (HTML, CSS and JavaScript).


The quieter you are, the more you are able to hear.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

I created one .js file.

In that I created an Ajax form and that Ajax form is having a checkbox which I want to check it when the value in the (Database)table in Y.

so in .js file how can i write the same script for the same.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Vishal Hegde wrote:I created one .js file.

In that I created an Ajax form and that Ajax form is having a checkbox which I want to check it when the value in the (Database)table in Y.

so in .js file how can i write the same script for the same.


JavaScript can not connect directly to the server so you will need to make an Ajax call back to a serverside page that can check the database for you. Other option is to have the page spit out the information you need in a script block when the page is rendering and the script uses that information.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61760
    
  67

Or if you are using JSP on the server, simply have the JSP set the attributes as appropriate before the page even reaches the browser.

As pointed out, JavaScript in the browser cannot directly access the DB.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i connect a js file to a database?