-1
我有一個從顯示這是從MySQL錯誤獲取PHP變量嵌入了
<?php
include('lib/db.php');
if(isset($_GET['id']))
{
$cid=mysql_real_escape_string($_GET['id']);
//echo $sub;
$rs=mysql_query("select * from category where id='$cid'");
$r=mysql_fetch_array($rs);
$q=rand(1,2);
$rs1=mysql_query("select * from questions where qid='$q'");
$r1=mysql_fetch_array($rs1);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test</title>
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript" src="js/tsubmit.js"></script>
</head>
<body>
<header>
<?php echo $r['cat_name'];?> Test
</header>
<form method="post" id="test" role="form">
<label for="question">Question:</label>
<?php echo $r1['question']; ?><br/>
<input type="radio" value="<?php echo $r1['ans1']; ?>" name="ans1" /><?php echo $r1['ans1']; ?>
<br/><input type="radio" value="<?php echo $r1['ans2']; ?>" name="ans1" /><?php echo $r1['ans2']; ?>
<br/><input type="radio" value="<?php echo $r1['ans3']; ?>" name="ans1" /><?php echo $r1['ans3']; ?>
<br/><input type="radio" value="<?php echo $r1['ans4']; ?>" name="ans1" /><?php echo $r1['ans4']; ?>
<br/><input type="submit" value="submit" name="submit" id="submit"/>
</form>
</body>
</html>
和嵌入式tsubmit.js獲取數據的問題網頁是
$(document).ready(function()
{
var start;
start= new Date()/1000;
function submit(x){
var end=new Date()/1000;
var timespent=end-x;
alert(timespent);
var ans=$('input[name=ans1]:checked').val();
alert(ans);
var cans="<?php echo $r['ans']; ?>";
//alert('<?php echo $r["ans"]; ?>');
alert(cans);
// var qid="<?php echo $q; ?>";
alert(qid);
//var datastring='ans='+ans+'×pent='+timespent+'cans='+cans+'qid='+qid;
$.ajax({
type:"POST",
url:"result.php",
data:'ans='+ans+'×pent='+timespent+'&cans='+cans+'&qid='+qid //success:success()
});
}
$("#test").submit(function(event){
alert('user clicked submit');
submit(start);
//event.preventDefault();
});
});
但我不是罐頭的價值,也result.php沒有得到任何
<?php
include('lib/db.php');
echo $_POST['ans'];
echo "<script> alert('ans')</script>";
?>
echo $_post['ans']
不獲取任何東西
請勿將技術從PHP直接轉換爲js環境。您可能會因語法錯誤而殺死腳本。總是使用'json_encode()'。 –
,並且您正在通過'