我想在jquery的$j
函数中增加$.each
。但$j
没有增加。可能是什么原因。我的代码如下:
$.ajax
({
url : "test.php",
type : "post",
data : {
"categoryIds" : categoryIds
},
dataType : "json",
success : function(resp){
var html = "";
var i = 1;
<?php $j = 1; ?>
$.each(resp,function(key,questions ){
<?php
$j = 1;
$testdataIndex = "answer_".$j;
?>
var test = "<?php echo $testdataIndex?>";
alert(test);
var res = "<?php echo $_SESSION['testdata'][$testdataIndex]; ?> ";
var index = "<?php echo $j++;?>";
alert(index);
});
});
每次test
打印'answer_1'和index
为1
答案 0 :(得分:-1)
修正了会话问题:
$.ajax
({
url : "test.php",
type : "post",
data : {
"categoryIds" : categoryIds
},
dataType : "json",
success : function(resp){
var html = "";
var i = 1;
<?php $j = 1; ?>
$.each(resp,function(key,questions ){
var testdataIndex = "answer_" + i ;
var filename = "getsession.php?sessionName="+testdataIndex;
$.get(filename, function (data)
{
sessionValues = data;
$("#"+testdataIndex).text(sessionValues);
});//get
html += '<textarea class="form-control answer" rows = "5" style="width:127%;" id="answer_'+i+'" name="answer_'+i+'" required="required"></textarea>';
i++;
});//each
});//ajax
<强> getsession.php 强>
<?php
session_start();
$sessionName = $_GET['sessionName'];
print ($_SESSION['testdata'][$sessionName]);
?>
对于遇到同样问题的其他人,我已回答了我的问题。