3

Is it possible, and how can I go about this?

karim79
  • 339,989
  • 67
  • 413
  • 406

3 Answers3

3

Yes, but with ajax help and server side script. jquery and JS doesn't support MySQL connection.

Thinker
  • 14,234
  • 9
  • 40
  • 55
2

Not directly but you can use Ajax to fetch content from a page generated by a server side language. Here is how to use Ajax with jQuery.

Sam Becker
  • 19,231
  • 14
  • 60
  • 80
2

Short answer:

No, you can't do that out of the box. JavaScript code runs in the browser, the MySQL-Database on the server. Browser-Javascript cannot run any code directly on the server (pfewww! :).

Long answer:

Some Web-Development-Frameworks expose the underlying database-structure in a well-defined (sometimes RESTful) manner in json:

In case of a hypothetical model 'User' in Ruby on Rails:

The list of all users, when issued as GET request. Creates a new User, when issued as POST.

/users.json 

Returns the User with the database-id 1, when issued as GET request. Updates the User with database-id 1 when issued as PUT-Request. Removes the object when issued as DELETE request.

/users/1.json

The returned json-code (JavaScript Object Notation) can easily be parsed using eval() in JavaScript. So here's a way to access your database using jQuery in semi-direct way :)

Hope this helps

flitzwald
  • 20,200
  • 2
  • 32
  • 28