正在加载下一篇文章

I am trying to load the next post on my website but once I click it says post not found. My code is below

<script>
$(document).ready(function(){
    $("button").click(function(){
        $.ajax({url: "{$baseurl}/view/{$p.key}", success: function(result){
            $("#haha").html(result);
        }});
    });
});
</script>

$p.key is the key of the post or id which is being loaded from the key column in the posts table.

The idea is to load the next id each time I click on the button.

Do you want to use template strings?

<script>
$(document).ready(function(){
    $("button").click(function(){
        $.ajax({url: `${$baseurl}/view/${$p.key}`, success: function(result){
            $("#haha").html(result);
        }});
    });
});
</script>