用jQuery查询MySQL数据库 [英] Query MySQL Database with jQuery
问题描述
大家好!
我想知道是否有可能使用jQuery(甚至是标准Javascript)查询MySQL数据库.我目前正在通过使用XMLHttpRequest和一些PHP代码来实现此目标.
Hello all!
I was wondering if it would be possible to query a MySQL database using jQuery (or even standard Javascript). I am currently achieving this goal by using a XMLHttpRequest, and some PHP code.
function getCount() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {
alert(xmlhttp.responseText);
return xmlhttp.responseText;
} else {
alert(xmlhttp.responseText);
return xmlhttp.responseText;
}
}
xmlhttp.open("GET", "scripts/php/get.php?v=myval", true);
xmlhttp.send();
}
这很好用,但是,我的目标是停止对PHP的过多依赖(不要误会我的意思,我喜欢PHP,我每天花费数小时最终用它开发东西).
我想要做的是查询我的数据,并将其存储为Javascript中的数组,然后能够使用jQuery处理数据...如果我仍然必须使用PHP,那很好,但我希望不必使用任何 echo 调用.
感谢您的帮助,
技嘉巨人
This works fine, but, my goal is to stop relying on PHP so much (don''t get me wrong, I love PHP, I spend hours on end developing things with it everyday).
What I want to be able to do, is query my data, and store it as an array in Javascript, and then be able to work with the data using jQuery... If I still have to use PHP, that''s fine, but I would prefer not having to use any echo calls.
Any help is appreciated,
Gigabyte Giant
推荐答案
请阅读我的评论.
我对jQuery的了解不尽如人意,但请检查以下内容:
http://stackoverflow.com/questions/8598659/how- can-i-use-jquery-to-run-mysql-queries [ http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql [ ^ ]
http://dev.mysql.com/doc/ndbapi/en/ndb-nodejs- setup.html [^ ]
正如我在评论中提到的那样,我建议编写 ASP.NET + MySQL Connector [ ^ ].
Please, read my comment.
I''m not familiar with jQuery as good as i whish, but please, check this:
http://stackoverflow.com/questions/8598659/how-can-i-use-jquery-to-run-mysql-queries[^]
http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql[^]
http://dev.mysql.com/doc/ndbapi/en/ndb-nodejs-setup.html[^]
As i mentioned (in the comment), i suggest to write ASP.NET + MySQL Connector[^].
这篇关于用jQuery查询MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!