• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can i connect a js file to a database?

 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Vishal Hegde
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic