在此脚本中,如何将轮的RESULT发送到PHP变量?
function stopRotateWheel() {
clearTimeout(spinTimeout);
var degrees = startAngle * 180 / Math.PI + 90;
var arcd = arc * 180 / Math.PI;
var index = Math.floor((360 - degrees % 360) / arcd);
ctx.save();
ctx.font = 'bold 30px sans-serif';
var text = restaraunts[index]
ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10);
ctx.restore();
}
更具体的“VAR TEXT = RESTARAUNTS [index]”
这可以发送到$ turnresult PHP变量吗?
答案 0 :(得分:0)
有几种方法可以做到这一点。让我们说你有:
function stopRotateWheel() {
clearTimeout(spinTimeout);
var degrees = startAngle * 180 / Math.PI + 90;
var arcd = arc * 180 / Math.PI;
var index = Math.floor((360 - degrees % 360) / arcd);
ctx.save();
ctx.font = 'bold 30px sans-serif';
var text = restaraunts[index]
ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10);
ctx.restore();
//this is an easy solution to pass in value of text to php
window.location.href = "myvar.php?text=" + text;
}
或者你可以用JQuery做到这一点:
<script type="text/javascript">
var text = '<?php echo $text ?>';
</script>
要向PHP发送Javascript值,您需要使用AJAX。使用jQuery,它将是这样的:
var text = 'data';
$.post('myvar.php', {variable: text});
答案 1 :(得分:0)
你可以简单地使用一些ajax。如果您有权访问jQuery,
var result = "<?php echo $someValue; ?>"; // or whatever else you'd like
$.ajax({
url: 'myscript.php',
type: 'POST',
data: "result=" + result,
success: function(success) {
alert(success);
}
});
看看这里:Jquery Ajax