JQUERY-存储php变量并在jquery脚本中回显它? [英] JQUERY - store php variable and echo it in jquery script?
本文介绍了JQUERY-存储php变量并在jquery脚本中回显它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将$ data变量发送到url:部分中的jquery脚本,以从不同的php文件获取源代码? (新手程序员). 我需要能够做这样的事情,例如:
Is it possible to send the $data variable to the jquery script in the url: section to get the source from different php files ? (newbie programmer). I need to be able to do something like this for example:
var source =
{
datatype: "json",
datafields: [
{ name: 'timeserver', type: 'time'},
{ name: 'val1', type: 'number'},
],
url: '<?php echo $data; ?>.php',
cache: false
};
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="jqwidgets/jqxchart.js"></script>
<script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// prepare the data
var theme = 'classic';
var source =
{
datatype: "json",
datafields: [
{ name: 'timeserver', type: 'time'},
{ name: 'val1', type: 'number'},
],
url: 'data.php',
cache: false
};
var dataAdapter = new $.jqx.dataAdapter(source,
{
autoBind: true,
async: false,
downloadComplete: function () { },
loadComplete: function () { },
loadError: function () { }
});
// prepare jqxChart settings
var settings = {
title: "Temperatura",
showLegend: true,
padding: { left: 5, top: 5, right: 5, bottom: 5 },
titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
source: dataAdapter,
categoryAxis:
{
text: 'Category Axis',
textRotationAngle: 0,
dataField: 'timeserver',
formatFunction: function (value) {
return $.jqx.dataFormat.formatdate(value, 'HH:mm:ss');
},
showTickMarks: true,
tickMarksInterval: Math.round(dataAdapter.records.length / 6),
tickMarksColor: '#888888',
unitInterval: Math.round(dataAdapter.records.length / 6),
showGridLines: true,
gridLinesInterval: Math.round(dataAdapter.records.length / 3),
gridLinesColor: '#888888',
axisSize: 'auto'
},
colorScheme: 'scheme05',
seriesGroups:
[
{
type: 'line',
valueAxis:
{
displayValueAxis: true,
description: 'Temperatura',
//descriptionClass: 'css-class-name',
axisSize: 'auto',
tickMarksColor: '#888888',
unitInterval: 5,
minValue: 10,
maxValue: 50
},
series: [
{ dataField: 'val1', displayText: 'Temperatura' }
]
}
]
};
// setup the chart
$('#jqxChart').jqxChart(settings);
});
</script>
<style type="text/css">
</style>
</head>
<body class='default'>
<!-- <div class="flip3D">
<div class="back">-->
<div style="width:670px; height:400px" id="jqxChart">
</div>
<!--</div>
<div class="front"><div style="width:670px; height:400px" id="jqxChart"></div></div>
</div> -->
<div class="flip3D">
<?php
// define variables and set to empty values
$data = $data1h = $data24h = $data7zile = $data1luna = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$data = test_input($_POST["gender"]);
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Arhiva</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Select:
<input type="radio" name="gender" value="data" >Curent
<input type="radio" name="gender" value="data1h" >Ultima ora
<input type="radio" name="gender" value="data24h" >Ultima zi
<input type="radio" name="gender" value="data7zile" >Ultima saptamana
<input type="radio" name="gender" value="data1luna" >Ultima luna
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo json_encode($data);
?>
</div>
</body>
推荐答案
var data = "<?php echo data; ?>";
上面的行在您的PHP模板/视图/控制器中
The above line goes in your PHP template/View/Controller
在jQuery中的用法:
usage in jQuery :
url : data + '.php'
这篇关于JQUERY-存储php变量并在jquery脚本中回显它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文