I’m trying to load information with ajax when my page loads but no information is displaying, can anyone spot what I’m doing wrong?
$(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 contains:
<?php
if(isset($_POST['artist'])) {
$artist = $_POST['artist'];
echo $artist;
}
echo "test";
?>
the html part of the page is fine
You need to change the value of the
successoption to be a reference to a function:Currently you are setting
successto the return value offinished, which isundefined. If you check your browser console you will likely be getting an error along the lines of “undefined is not a function”.