Get HTML and JS database connection

Asked

Viewed 17,687 times

1

How to get the connection to the database via SOAP using HTML and Javascript? I use Jquery Mobile. I am Making a login system, and I need to transport the input information to the Worklight Adapter to connect to the database and return the sucess or fail messages and, if successful, advance the login screen.

  • You necessarily need a language server side like PHP, Ruby, Python, others... Only with HTML and Javascript is impossible!

  • It is not a broad question, on the contrary, it is an extremely limited question.

  • 1

    is quite limited what I want.. I ask you to re-evaluate

3 answers

3


You shouldn’t use Javascript to access databases for many reasons, but if you really want to do this, here’s an example:

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
   document.write(rs.fields(1));
   rs.movenext;
}

rs.close;
connection.close; 

A good way to do this would be using secondary languages such as PHP, Java, etc. NET.

I hope I’ve helped.

  • Yes! Thank you very much @jpklzm

  • 1

    While it works, and helps, as @jpklzm itself says "You shouldn’t be using Javascript to access databases for various reasons," I recommend that you look for another, more appropriate solution, because using database connection in javascript leaves your application totally unsafe. In javascript I would recommend using ajax to communicate with some language on the server (java, php, c#), and yes you make your application communicate with the database.

  • Thank you @Ericosouza!!

0

No, it is not possible to consider using webservices and communicating with jquery ajax.

  • Hello @Hiago, do you have any article where I might be learning about this?

  • You would have to first learn how to build a SOAP service, I don’t know if you know php anymore I think it will be easy for you to learn, so you can study how to consume SOAP webservice in PHP with jquery ajax. Because it has several ways, it is not a tutorial but several that you will have to research, more is that. 1º - Creating SOAP service in php. 2º - Consuming SOAP service in php with jquery ajax. And the rest is logic and imagination expensive.

  • This does not provide an answer to the question. To criticize or request clarification from an author, leave a comment below its publication.

  • Renan’s question was: "is it possible ?" Answer: "No"! At no time have I criticized only a suggestion, but I believe that the question was answered if it was not, put a correct answer.

  • Hiago, I agree with you, that answers the question. However, the more detailed the answer, the better. This @Brunoaugusto comment came from site analysis system, and his reply went there automatically because it was too short (therefore, the system suspected it would look better as a comment, by the length).

  • All right, I just wanted to say that at some point my answer is incorrect, I apologize because they always help me here and I just wanted to reciprocate in some way, I just didn’t know how to detail more.

  • Yes, no need to apologize. I just wanted to give you a hint of how the system works. Every time you post an answer, try to include more details explaining the problem. Otherwise the answer will automatically stop in the peer review system, and may end up deleted by other users. Your answer is on the boundary between a reply and a comment.

  • Got it thanks, and sorry @Brunoaugusto if I seemed thick.

  • A good alternative to SOAP, and I think simpler, is to use REST (or webapi). Especially for those who will start on webservices. Here are some references: http://eduardopires.net.br/2013/07/asp-net-web-api-meu-primeiro-servico-rest/ http://www.infoq.com/br/articles/rest-introduction

Show 4 more comments

0

Communication cannot be handled without the use of a Web Service. I noticed in your last question (which you deleted), that you are trying to work with Worklight, so I suggest you that reading

  • Hi Rafael, thank you for participating, but I really need to connect with a non-local database.. I’ve seen this article when I was still working at IBM itself! As for Webservices, would you advise me some reading that might help me? Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.