[英]jquery- how to run ajax in document ready?
我正在嘗試在頁面加載但沒有信息顯示時使用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
。 如果您檢查瀏覽器控制台,則可能會在“未定義不是函數”方面出現錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.