请查看数据:{limit: lim , offset: off, personname: $personname, fname: $fname},
这是将数据从当前php
传递到ajax
的正确方法吗?
<?php
$personname='Prakash';
$fname='';
$surname='';
?>
<script>
function displayRecords(lim, off) {
$.ajax({
type: "GET",
async: false,
url: "getrecords.php",
data: {personname: $personname, fname: $fname},
success: function(html) {
$("#results").append(html);
}
});
}
</script>
答案 0 :(得分:3)
在你的代码中,你必须这样写:
php variable
中的 JavaScript
应写为'<?php echo $val;?>'
<?php
$personname='Prakash';
$fname='';
$surname='';
?>
function displayRecords(lim, off) {
$.ajax({
type: "GET",
async: false,
url: "getrecords.php",
data: {limit: lim , offset: off, personname: '<?php echo $personname;?>, fname: '<?php echo $fname?>'},
beforeSend: function() {
$("#loader_message").html("").hide();
$('#loader_image').show();
},
success: function(html) {
$("#results").append(html);
$('#loader_image').hide();
}
});
}
答案 1 :(得分:1)
<?php
$personname='Prakash';
$fname='';
$surname='';
?>
<script>
function displayRecords(lim, off) {
$.ajax({
type: "GET",
async: false,
url: "getrecords.php",
data: {limit: lim , offset: off, personname: <?php echo $personname;?>, fname:<?php echo $fname;?>},
beforeSend: function() {
$("#loader_message").html("").hide();
$('#loader_image').show();
},
success: function(html) {
$("#results").append(html);
$('#loader_image').hide();
}
});
}
</script>
答案 2 :(得分:0)
PHP variable
passed
应该jquery
,如下所示
data: {personname: '<?php echo $personname; ?>', fname: '<?php echo $fname; ?>'},