If action is on a different page do I use fwrite function



PHP Snippet 1:

// this is your ajax file, ajax.php


<?php

    $email = $_POST['EMAIL']; // your form method is post, no need for $_REQUEST
    $file = fopen("document.txt","a+");
    $write = fwrite($file,$email . "\n");

    echo $write ? "Success" : "Fail";
?>

PHP Snippet 2:

<script>

    function executeAjax() {
        $.ajax({
                 url: 'ajax.php',
                 type: 'POST',
                 data: {EMAIL: $("#subscribe-form1").find("input[type='email']"},
                 success: function(data) {
                     alert(data); return false;
                     document.getElementById("subscribe-form1").submit();
                 },
                 error: function(e) {
                     alert('There was a problem...please try again');
                 }
        });
    }

    $(document).ready(function () {
        $("button").click(function () {
            executeAjax();
        });
    });
</script>