Home  >  Article  >  Backend Development  >  jq调用数据库,该怎么处理

jq调用数据库,该怎么处理

WBOY
WBOYOriginal
2016-06-13 11:52:581114browse

jq调用数据库

var zjl = false;<br />			var num = 0;<br />			var goon = true;<br />			$(function() {<br />				$("#scratchpad").wScratchPad({<br />					width: 150,<br />					height: 40,<br />					color: "#a9a9a7",<br />					scratchMove: function() {<br />						num++;<br />					 if (num == 2) {<br />					  var a = "一等奖";<br />					  var b = "二等奖";<br />					  var c = "三等奖";<br />					  var e = "幸运奖";<br />					  var d = "谢谢参与";<br />					  var aa = 0.000;//一等奖的概奖<br />					  var bb = 0.001;//二等奖的概率<br />					  var cc = 0.004;//三等奖的概率<br />					  var ee = 0.996;//幸运奖的概率<br />					  var dd = 0.000;//未中奖的概率<br />					<br />					  var shows = [a, b, c,d,e];<br />					  var prob = [aa, bb, cc,dd,ee];<br />					  var len = 1000;<br />					  var probLen = [len*aa, len*bb, len*cc, len*dd, len*ee];<br />					  var ran = Math.random() * len;<br />					  for(var i = 0; i < probLen.length; i++){<br />					   var ranStart = 0;<br />					   for(var j = 0; j < i; j++){<br />						ranStart += probLen[j];<br />					   }<br />					   var ranEnd = ranStart + probLen[i];<br />					<br />					   if(ran > ranStart && ran <= ranEnd){<br />						<br />								var award = shows[i];<br />								if(shows[i]!='谢谢参与')<br />								{<br />									zjl = true;<br />								}<br />								<br />								document.getElementById('prize').innerHTML = award;<br />								$("#theAward").html(award);

其中a b c d e  aa bb cc dd ee 怎么能获取数据库的值呢?
------解决方案--------------------
jq不能读取数据库。

可以用php等脚本语言获取,再写入js变量.
例如:
<br /><?php<br />    $data = '{"aa":1,"bb":2,"cc":3,"dd":4}' // 这里也可以从db获取<br />?><br /><script type="text/javascript"><br />    var data = <?=$data ?>;<br />    var aa = data['aa'];<br />    var bb = data['bb'];<br />    var cc = data['cc'];<br />    var dd = data['dd'];<br />    alert('aa:' + aa + ' bb:' + bb + ' cc:' + cc + ' dd:' + dd);<br /></script><br />

------解决方案--------------------
jquery不能读取数据库,而且也不安全,你可以用jquery与后端交互,或者你用nodejs也可以

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn