'How to get AJAX to post on second page?

This is what is happening: I send data but and I have it coded to echo out on second page. However, it just echoes out on first page. How do I make it so it echoes out on second page not the first page?

The code on second page executes but it executes on first page. I want it on second page.

<!doctype html> FIRST PAGE
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div class="text-center"><a href="#" class="btn btn-grn" id="scaleButton">Button</a></div>
<input class="form-control" name="cartID" id="cartID" type="hidden" value="<?php echo $order['clientid'] ;?>">
    <p id="edit_box"></p>
<script>
    
$("#scaleButton").click(function()  { 
var cartID = "hello"
var second = "second";
    
///////// AJAX //////// AJAX //////////
    $.ajax({
        type: 'POST',
        url:  'user/testing1234.php',
        data: {first:cartID,second:second},
        success: function( response ){
            alert('ajax');
            $('#edit_box').html(response);//this is where you populate your response
        }//close succss params
    });//close ajax
///////// AJAX //////// AJAX //////////
})
</script>


</body>
</html>


SECOND PAGE
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>

<?php
$first = $_POST['first'];
$second = $_POST['second'];
$third = $_POST['third'];


echo $second;
echo $second;
echo $second;
?>


</body>
</html>


Solution 1:[1]

This is what I need I believe:

$( document ).ready(function() {

$("button").click(function() {
var dataPoint = "chunk of data";
    ///////// AJAX //////// AJAX //////////
        $.ajax({
            type: 'POST',
            url:  'some_page_name.php',
            data: {dataPoint:dataPoint},
            success: function( response ){
                $('#success').html("Sent!!");
            }
        });
    ///////// AJAX //////// AJAX /////////

  });

And for your HTML Page:

<button>Click me</button>
<div id="success"></div>

Modify as needed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 technology101010