当我的页面加载时,我尝试使用ajax加载信息,但没有显示任何信息,有人能发现我做错了什么吗?
$(document).ready(function (){
$.ajax({
url: 'ajax_load.php',
type: "post",
data: "artist=<?php echo $artist; ?>",
dataType: 'html',
beforeSend: function() {
$('#current_page').append("loading..");
},
success: finished(html),
});
});
function finished(result) {
$('#current_page').append(result);
};
ajax_load.php 包含:
<?php
if(isset($_POST['artist'])) {
$artist = $_POST['artist'];
echo $artist;
}
echo "test";
?>
页面的html部分很好
最佳答案
您需要将 success
选项的值更改为对函数的引用:
$(document).ready(function (){
$.ajax({
url: 'ajax_load.php',
type: "post",
data: "artist=<?php echo $artist; ?>",
dataType: 'html',
beforeSend: function() {
$('#current_page').append("loading..");
},
success: finished //Change to this
});
});
当前您将success
设置为finished
的返回值,该值是undefined
。如果您检查浏览器控制台,您可能会收到类似“未定义不是函数”的错误。
关于php - jquery-如何在准备好的文档中运行ajax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10602323/