Here is my code,
<?php
$answers = Array( [0] => 13 [1] => 5 [2] => 6 [3] => 11 );
?>
<script>
function loadData1(val) {
var dataToSend = {
'name': val,
'ans[]': <? php echo $answers; ?>
};
$.ajax({
type: 'POST',
data: dataToSend,
url: '<?php echo JURI::ROOT();?>classfiles/sample.php',
success: function (data) {
$('#questions').html(data);
}
});
}
</script>
I want the array values in sample.php
file, but I don't get any output.
Any useful answers are really appreciated.
Here is my code,
<?php
$answers = Array( [0] => 13 [1] => 5 [2] => 6 [3] => 11 );
?>
<script>
function loadData1(val) {
var dataToSend = {
'name': val,
'ans[]': <? php echo $answers; ?>
};
$.ajax({
type: 'POST',
data: dataToSend,
url: '<?php echo JURI::ROOT();?>classfiles/sample.php',
success: function (data) {
$('#questions').html(data);
}
});
}
</script>
I want the array values in sample.php
file, but I don't get any output.
Any useful answers are really appreciated.
Share Improve this question edited Mar 26, 2013 at 6:53 Maehler 6,3411 gold badge43 silver badges48 bronze badges asked Jan 24, 2013 at 9:58 BasithBasith 1,0757 silver badges22 bronze badges 2-
sample.php just contains
<?php $answers = Array ( [0] => 13 [1] => 5 [2] => 6 [3] => 11 ); ?>
? – user1157393 Commented Jan 24, 2013 at 10:01 - 1 have a look at turning your array into a JSON string. – azzy81 Commented Jan 24, 2013 at 10:03
1 Answer
Reset to default 7The line:
var dataToSend = {'name' : val, 'ans[]' : <?php echo $answers; ?> } ;
will print:
var dataToSend = {'name' : val, 'ans[]' : Array } ;
which creates a javascript syntax semantic error (ans = empty string will be posted). Change to:
var dataToSend = {'name' : val, 'ans[]' : <?php echo json_encode($answers); ?> } ;
which prints:
var dataToSend = {'name' : val, 'ans[]' : [13,5,6,11] } ;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742340395a4425508.html
评论列表(0条)