0

Using a simple form to send data to an API endpoint via AJAX, however, the form data doesn't seem to be making it to the endpoint and I can't for the life of me figure out what's going wrong here.

Form:

<form id="newLink">
        <p class="label">Destination:</p>
        <input placeholder="https://website.com/page" name="destination" type="text" />
        <button type="submit" id="submitLink"><img class="logo" src="assets/images/bomb.png" /></button>
</form>

JS:

$("#submitLink").click(function(){ 
    var newLink = new FormData($('#newLink')[0]);
    $.ajax({
        type: "POST",
        url: "api/submitLink.php",
        data: newLink, 
        processData: false,
        contentType: false,
        cache: false,
        success: function(data) {
            console.log(data);
        }
    });

    return false;

});

PHP:

$something = $_post['destination'];
echo 'data: ' . $something;
Nick Tirrell
  • 441
  • 2
  • 13

0 Answers0