I have to develop a website for mobile phones and I am using html5 and javascript. Can I access/insert into server database using html5 and javascript only without using asp, php or any other server side language.
Yes it is. You will however need a backend database with a HTTP interface. One of which is MongoDB which has a REST interface.
More info here http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON
No, you can't, and if you could then you would be insane to do so as it would allow everybody to make arbitrary SQL queries.
Html and Javascript are the Front end side languages, it not advisable to use those languages features to connect to database. Later it would be very tough to maintain it and enhance it.
ALWAYS THINK IN FUTURE PERSPECTIVE, else your code becomes obsolete
instead you can use any scripting language like php to connect to database.
Since you wanted to create a website, obviously PHP and mysal will be always available to you at NO COST.
Use javascript and maybe you may not want to connect to mysql... Try .csv formats and excel... It's good if you are not storing sensitive information.
Related
I only plan to use html, mysql, javascript and jquery.
I know learning php will be a great help in the future but it will take me too long to learn everything in a week.
For the sever side I use servlets..
Thank you
As far as I know, no. Well, strictly speaking, you don't need PHP, but you will need some server-side technology.
Assuming the data you need to autocomplete exists in mySQL, and you use jQuery.ajax() or similar to get the information on the fly, you still need some data access layer in between, which is where PHP or similar comes in. Of course, if you're accessing data that has been exposed by an API, you might have better luck.
MySQL runs on your server, but the browser can't open a socket directly to it to do queries. See: How to Use Sockets in JavaScript\HTML?
So you will need something on the server that talks to MySQL and responds back to your jQuery code. I'm all with you that you don't want to learn PHP. If you already know javascript, you can use node.js on the server. It has libraries to talk to MySQL: MySQL with Node.js
You won't be able to connect to your mySQL database directly using Javascript running on the client. The only possible way I can imagine is using another database system which offers an HTTP-interface (such as Apache Cassandra) or using a plugin for mySQL which does this job (I could not find an officially supported one, maybe you got more luck). This way, you could query data using Javascript/Ajax directly from your client.
But keep attention to security concerns, such as SQL injections or handling of client connections, which gets much more complex if you are not using a middle tier (PHP, nodejs, Java, etc.) running on a web server.
You have to use any server side technology for autocomplete. Without using any server side technology you can't create autocomplete (you can do it by adding some dummy records)
I found third party plug ins to do this
devbrige,
intellesense,
jquery auto complete
http://www.techyari.in/2014/04/jquery-autocomplete-ajax-tutorial-j2ee-json-mysql.html
https://github.com/devbridge/jQuery-Autocomplete
though I am still trying to work the codes out
How can I connect to mysql DB from JS function?
I found this question:
How to connect to SQL server database from javascript?
but it doesn't work on Chrome, because they're using ActiveXObject.
Thank you.
There is no good solution on web browser side which will allow you to work with all browsers. There are many disadvantages to work with database on browser site.
First of all, you show your database structure and it is very dangerous. Imagine, how easier is to make SQL-injection while you know tables and fields?
You have to establish connection in some way using password which will be shown to third party users. Or you have to set password-less connection, which is also dangerous.
When you establish connection with database, somebody can easly execute own query what is trivial, because you are showing your structure.
I strongly recommended you to not do it on browser side.
but I have cross-domain problem, so I just need to do simple select from db
Direct browser-to-database communication is definitely not a proper solution.
If you want to get a list of values out of the db, just write a method in whatever server-side language you prefer (or need) to use, make the client-side JavaScript code call that method through its public URI and parse the response body into some data structure.
A more general solution to this kind of problems is XMLRPC (for the record, I've used it under Code Igniter / Flash ActionScript 3.0), though it's not all that simple to use.
If you need to get data from two different domains, then implement the above on both of them and make the JavaScript code call the two different URIs and combine the data (if needed).
You must use AJAX, because JavaScript itself can't connect to server. You can call some PHP script with AJAX and in JavaScript handle response from it. See jQuery.ajax().
make Ajax call from your javascript to php which connects you to database
Without some sort of plugin, or sending requests to a server side application that will access the database for you, you can't. So focus on those instead, specially server side apps.
A comment under this question
How to make a database connection
suggests that's only possible with a particular mix of Microsoft technologies specifically designed to deploy desktop-like software using a web browser. The bits mentioned there are:
HTA - HTML Applications
JScript - a Microsoft flavor of JavaScript
ActiveX objects
A link is also provided: Introduction to HTML Applications (HTAs)
What would be the best way to write some values into a xml file?
In the .html file i have a certain score that gets its values from a js file called jsfuncions.js
Tried looking on several sites for this but never found a clear and simple answer.
Do i have to place the writer into my index file with script tags directly?
Also do i have to use the var xml = new xmlwriter(); Or is there something more simple in jquery to fit this purpose?
Pretty sure i have to use var XML = new XMLWriter();
But there is simply nothing to be found about this funcion. Can anyone point me in the right direction for a simple writer?
Regards.
JavaScript can not update the XML file permanently. You will need to use a serverside language to make the changes permanent.
Browser security sandboxing will prevent a web page being able generate a file and save it locally.
The only local persistence you can use is cookies - you could look at JSON format for storing records with properties and values inside a cookie - limitations are the max size allowed of the cookie.
There's a new local storage mechanism arriving with HTML5 which some of the latest browsers support.
http://people.w3.org/mike/localstorage.html
It really depends what you want to do with the resulting XML. If you want to save information entered by users, then you'll need to use a server side technology for the save operation.
Examples of server side technology include ASP.NET, PHP, Ruby on Rails, Java and Node.js. If you have no experience with any of these technologies, this will be your biggest learning curve. Microsoft provide a fantastic free application called WebMatrix which will help you get started with a number of different frameworks, but excels at ASP.NET.
If you're only interested in persisting information for the use of an individual user, you'll not be looking at an actual XML file. #BobTodd's answer gives a list of most of your options, but I would say the choice comes down to Cookie vs. local storage. The choice will be made based on the volume of information you would like to save. Cookies are a lot simpler, but only allow a small amount of data to be saved.
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 not 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.
No you can't simply do that.
Javascript was created for Client Side which means it can be effective at Client Side.
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.
Does javascript coding work better with any particular server language?
No. Client Side JavaScript is unaffected by the language used to code the server side processing.
If you are planning to do any kind of XML/"AJAX" stuff, make sure that your language of choice on the server side has robust XML and JSON libraries. If you aren't using it in this manner, it shouldn't make any difference. Having proper libraries will save you a lot of headache later on since you won't be forced to build your own.
The short answer is no.
The long answer is that, no, but you should still simplify the interface between your server-side code and JavaScript:
Use a standardized data serialization format (XML or JSON being the most popular forms). Make sure your serializers and parsers are symmetric; i.e. that you can freely read and generate data on both sides. Do not assume you will always be reading on the client and writing on the server.
Limit manually crafting JavaScript on the server side to a minimum. Try not to dump JavaScript functions with inline script blocks. Try attaching event listeners to elements with JavaScript instead of using onclick or href="javascript:".
No, but there is better integration in certain situations, where server-side code will generate javaScript automatically, such as the .NET framework and the Google Web Toolkit.
Presuming that you mean client-side JavaScript, no. By the time that JavaScript is executing, it's in an environment where server-side code isn't visible. In fact, it would be tricky for JavaScript to even determine what server-size environment created the document it's acting on. All it sees is the output.
Client Side javascript is bound to the browser and not to any specific language. It is all based on the actual output of your server to the clients browser.
Perhaps the question should be - how or why would the server language make a difference. In the end text is being spit out which is possible regardless of language/platform.
If you have javascript on the serverside, you can share code- For instance by doing client side form validation, and using the same validation code on the server before submitting it to a database.